在CentOS 7/RHEL 7上安装MariaDB服务器

时间:2019-08-20 17:58:23  来源:igfitidea点击:

安装MariaDB服务器

安装MariaDB服务器和MariaDB客户端

yum install mariadb-server mariadb

查询与MariaDB相关的rpm包列表

[root@localhost ~]# rpm -qa|grep -i maria
mariadb-5.5.37-1.el7_0.x86_64
mariadb-server-5.5.37-1.el7_0.x86_64
mariadb-libs-5.5.37-1.el7_0.x86_64
[root@localhost ~]#

启动MariaDB服务器:

systemctl start mariadb.service

启动/停止/重启MariaDB服务器

在CentOS 7中启动MariaDB服务器

systemctl start mariadb.service

在CentOS 7中停止MariaDB服务器

systemctl stop mariadb.service

在CentOS 7中重新启动MariaDB服务器

systemctl restart mariadb.service

在CentOS 7中查看MariaDB服务器的状态

systemctl status mariadb.service

在CentOS 7中设置系统启动时启用MariaDB服务器

systemctl enable mariadb.service

在CentOS 7中禁用MariaDB服务在开机时启动

systemctl disable mariadb.service

了解MariaDB服务器的活动状态。

systemctl is-active mariadb.service

重置密码

重新安装MariaDB服务器后,数据库root用户的密码为空。

出于安全原因,重置root用户的密码非常重要。

方法1:使用mysql_secure_installation命令重置root密码

[root@localhost ~]# 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, well need the current
password for the root user.  If youve just installed MariaDB, and
you havent 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] y 是否设置root密码
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] y 是否删除匿名用户
 ... 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] y 是否允许root用户远程登录
 ... 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] y 是否删除test数据库
 - 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] y 是否重新加载权限表
 ... 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@localhost ~]#

方法2:登录MariaDB服务器重置root密码

登录到MariaDB服务器

mysql -u root

在MariaDB服务器中运行下面的命令来重置root的密码。

use mysql;
update user set password=PASSWORD("新的root密码") where User='root';
flush privileges;
quit