mariadb数据库服务
admin
2023-06-06 05:41:20
0


什么是mariadb?
       MariaDB数据库管理系统是MySQL的一个分支,主要由开源社区在
维护,采用GPL授权许可 MariaDB的目的是完全兼容MySQL,包括API和
命令行,使之能轻松成为MySQL的代替品。在存储引擎方面,使用XtraDB
(英语:XtraDB)来代替MySQL的InnoDB。    MariaDB由MySQL的
创始人Michael Widenius(英语:Michael Widenius)主导开发,他早
前曾以10亿美元的价格,将自己创建的公司MySQL AB卖给了SUN,此后,
随着SUN被甲骨文收购,MySQL的所有权也落入Oracle的手中。MariaDB
名称来自Michael Widenius的女儿Maria的名字。

1.Mariadb安装  

    1-1安装mariadb和mariadb-client组件:    
        # yum groupinstall -y mariadb mariadb-client  
    1-2启动mariadb服务:    
         # systemctl start mariadb ; systemctl enable mariadb  
[root@server1 ~]# ss -antple|grep mysql
LISTEN     0      50                        *:3306                     *:*      
users:(("mysqld",2622,13)) uid:27 ino:36479 sk:ffff8800235a0000 <->

    1-4编辑/etc/my.cnf文件,在[mysqld]中加入以下参数:        
        skip-networking=1    
    1-5# systemctl restart mariadb      
        # ss -antlp |grep mysql     此时只允许通过套接字文件进行本地连接,阻断
        所有来自网络的tcp/ip连接。
2.使用mysql_secure_installation工具进行数据库安全设置,根据提示完成
   操作:
 
          # mysql_secure_installation
[root@server1 ~]# mysql_secure_installation
/usr/bin/mysql_secure_installation: line 379: find_mysql_client: command not found

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
     SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

In order to log into MariaDB to secure it, we'll need the current
password for the root user.  If you've just installed MariaDB, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.

Enter current password for root (enter for none):
OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.

Set root password? [Y/n]
New password:
Re-enter new password:
Password updated successfully!
Reloading privilege tables..
... Success!


By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them.  This is intended only for testing, and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.

Remove anonymous users? [Y/n]
... Success!

Normally, root should only be allowed to connect from 'localhost'.  This
ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n]
... Success!

By default, MariaDB comes with a database named 'test' that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.

Remove test database and access to it? [Y/n]
- Dropping test database...
... Success!
- Removing privileges on test database...
... Success!

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now? [Y/n]
... Success!

Cleaning up...

All done!  If you've completed all of the above steps, your MariaDB
installation should now be secure.

Thanks for using MariaDB!
[root@server1 ~]#

3.登录数据库:    

          # mysql -u root -p Enter password: redhat MariaDB [(none)]> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | +--------------------+ 3 rows in set (0.00 sec) MariaDB [(none)]> quit
4.数据库基本操作SQL
show databases;                            显示数据库 use mysql;                            进入数据库 show tables;                            显示数据库中的表 desc user;                            查看user表的数据结构 flush privileges;                        刷新数据库信息 select host.user,password from user;                查询user表中的host,user,password字段 create database westos;                        创建westos数据库 use westos;                             create table linux(                        创建表,username,password字段 username varchar(15) not null, password varchar(15) not null ); select * from mysql.user;                    查询mysql库下的user表中的所以 alter table linux add age varchar(4);                添加age字段到linux表中 alter table linux drop age; alter table linux add age varchar(4) after username; show tables; desc linux; insert into linux values ('user1','passwd1');                在linux表中插入值为username = user1,password = password1 update linux set password=password('passwd2') where username=user1;    更新linux表中user1 的密码为password2 delete from linux where username=user1;                    删除linux表中user1的所以内容
5.mysql 密码恢复  
          1)#systemctl stop mariadb  
          2)#mysql_safe --skip-grant &  
          3)#mysql        
          update mysql.user set password=password('westos') where user='root';    更新mysql.user 表中条件为root用户的密码为加密westos   4)killall -9  mysqld_safe     ps -aux | grep mysql     kill -9 ****    5)systemctl start mariadb
6.用户和访问权限
创建用户CREATE USER wxh@localhost identified by 'westos'; CREATE USER lee@'%' identified by 'redhat';用户授权GRANT INSERT,UPDATE,DELETE,SELECT on mariadb.* to wxh@localhost; GRANT SELECT on mariadb.* lee@'%';重载授权表FLUSH PRIVILEGES;查看用户授权SHOW GRANTS FOR wxh@localhost;撤销用户权限REVOKE DELETE,UPDATE,INSERT on mariadb.* from wxh@localhost;删除用户DROP USER wxh@localhost;
7.备份与恢复
备份# mysqldump -uroot -predhat westos > westos.dump # mysqldump -uroot -predhat --all-databases > backup.dump # mysqldump -uroot -predhat --no-data westos > westos.dump   ##只备份框架,不备份数据。恢复# mysqladmin -uroot -predhat create db2 或 mysql -uroot -predhat -e 'CREATE DATABASE db2;' # mysql -uroot -predhat db2 < westos.dump
8.网页管理数据库
1)装软件http,php,php-mysql  (phpMyAdmin-3.4.0-all-languages) 2)cd /var/www/html 3)下载解压php压缩包, 4)mv phpMyAdmin-3.4.0-all-languages/   myadmin   5)cd myadmin/ 6)cp config.sample.inc.php  config.inc.php   vim config.inc.php        $cfg['blowfish_secret'] = '';       ==>$cfg['blowfish_secret'] = 'steven';   7)systemctl restart httpd   8)172.252.254.X/myadmin    
数据库备份脚本
#!/bin/bash HELLO=$1.`date +%Y-%m-%d`.sql read -p "please input your  user name :"  NAME read -s -p "please input the user password :" PASSWORD mkdir /mydata  &>/dev/null touch /mydata/$HELLO mysqldump -u$NAME -p$PASSWORD  $1 >/mydata/$HELLO echo -e  "\nThe backup successful!"

  
  


相关内容

热门资讯

美国特勤局:白宫附近枪击案嫌疑... 央视记者当地时间5月23日获悉,美国特勤局表示,当天白宫附近枪击案嫌疑人在医院死亡。美国特勤局表示,...
浙江宣传:年轻干部,不要怕普通 有没有那么一瞬间,你会觉得自己很普通,置身人潮人海中没有任何特别之处?其实,普通既是初入职场的年轻干...
Find My进入第三方时代:... 新闻引入 2026年1月,苹果发布AirTag 2代,精确查找范围提升50%、扬声器音量提升50%,...
精密散热行业的技术跃迁:从“被... 在功率密度持续攀升、热流密度逼近物理极限的行业节点,精密散热已经从一个“辅助性功能模块”演变为决定系...
湖南衡阳发生火灾致5死1伤 5月24日0时45分,衡阳市祁东县上正社区一商铺发生火灾,造成5人死亡,1人受轻微伤,伤者正在积极救...
警惕!澳大利亚密集加码关键矿产... 5月18日,澳大利亚以“国家安全”为由,向北方矿业公司6名与中国有关联的股东发出强制出售令,要求在1...
AI行情狂热,三星电子未成年股... 近段时间,AI行情再次成为全球资本市场主线,但舞台中央的“主角”发生了变化:投资者不再只偏好云厂商和...
俄称乌无人机袭击卢甘斯克一学校... 当地时间5月23日,据俄罗斯紧急情况部通报称,遭乌方袭击的斯塔罗比尔斯克职业学院死亡人数升至21人,...
美加州故障化学品储罐持续升温,... 新华社洛杉矶5月23日电(记者高山 谭晶晶)美国加利福尼亚州南部奥兰治县官员23日说,当地21日开始...
真实感,AI时代写作的生命力所... AI时代,对于许多人来说,因为有了各种智能工具的加持,写作似乎变得容易了。通过提出命题、投喂内容,无...