CentOS7 安装MariaDB

Posted 胡金水

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了CentOS7 安装MariaDB相关的知识,希望对你有一定的参考价值。

1.安装MariaDB

[root@localhost server]# yum install mariadb-server

2.启动MariaDB服务

# 启动MariaDB
[root@localhost server]# systemctl start mariadb
# 设置开机自动启动MariaDB
[root@localhost server]# systemctl enable mariadb

3.设置mysql核心配置

[root@localhost server]# mysql_secure_installation
# 直接按回车
Enter current password for root (enter for none):
# 是否设置密码
Set root password? [Y/n] y
# 是否移除匿名用户
Remove anonymous users? [Y/n] y
# 是否拒绝远程登录
Disallow root login remotely? [Y/n] n
# 是否移除test数据库
Remove test database and access to it? [Y/n] y
# 是否重载权限表
Reload privilege tables now? [Y/n] y

4.修改mysql权限表配置

[root@localhost server]# mysql -u root -p
MariaDB [(none)]> use mysql;
MariaDB [mysql]> select host,user  from user;
+-----------------------+------+
| host                  | user |
+-----------------------+------+
| 127.0.0.1             | root |
| ::1                   | root |
| localhost             | root |
| localhost.localdomain | root |
+-----------------------+------+
4 rows in set (0.00 sec)
# 删除这两个配置
MariaDB [mysql]> delete from user where host in ('::1','localhost.localdomain');
# 添加一个通用配置
MariaDB [mysql]> insert into user (host,user) values ('%','root');
MariaDB [mysql]> select host,user  from user;
+-----------+------+
| host      | user |
+-----------+------+
| %         | root |
| 127.0.0.1 | root |
| localhost | root |
+-----------+------+
3 rows in set (0.00 sec)
# 刷新权限表
MariaDB [mysql]> flush privileges;
# 退出
MariaDB [mysql]> exit
# 重启服务
[root@localhost server]# systemctl restart mariadb
# 关闭防火墙
[root@localhost server]# systemctl stop firewalld

5.使用数据库客户端连接测试

CentOS安装MariaDB_测试是否连接成功

注意:

如果你使用数据库客户端连接,可能会遇到这种问题:

1045-Access denied for user 'root'@'localhost' (using password: YES)错误处理
解决方案:
#执行授权命令【GRANT ALL PRIVILEGES ON *.* TO '数据库用户名'@'“%”标识不限制IP' IDENTIFIED BY '数据库密码';】
MariaDB [mysql]> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'root';
# 刷新权限表
MariaDB [mysql]> flush privileges;

以上是关于CentOS7 安装MariaDB的主要内容,如果未能解决你的问题,请参考以下文章

mariadb安装后存在centos7哪个目录下

Centos7安装 mariadb启动错误解决

centos7下安装mariadb

centos7安装mysql(MariaDB)

centos7 Mariadb 安装

CentOS7 安装MariaDB