安装与配置MariaDB数据库

1,yum安装MariaDB

[root@vm7 ~]# yum -y install mariadb-server mariadb-client mariadb
[root@vm7 ~]# systemctl start mariadb  #启动mariadb
[root@vm7 ~]# mysql -uroot 
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 2
Server version: 5.5.68-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]
> use mysql;  #选中mysql数据库 MariaDB [mysql]> update user set authentication_string=password('password') where user='root';  #配置登录密码 Query OK, 4 rows affected (0.00 sec) Rows matched: 4 Changed: 4 Warnings: 0

 

修改密码不生效:

MariaDB数据库管理系统是 MySQL 的一个分支,主要由开源社区在维护,采用GPL授权许可 MariaDB的目的是完全兼容MySQL,包括API和命令行,使之能轻松成为MySQL的代替品。

在新版的Mariadb安装过程中没有设置密码的过程了,而用mysql_secure_installation命令设置Root密码,然后用phpmyadmin登录发现提示 Access denied for user ‘root’@‘localhost’

而在命令行你发现直接用mysql就可以登录数据库,完全不用密码,然而你用其他的mysql管理工具使用密码无论如何都会提示 Access denied for user ‘root’@‘localhost’ 。搜索了一下,原来不是我们安装或者操作除了问题,是Mariadb
在5.2.0以后的版本默认不再使用密码认证了,改用Authentication Plugin - Unix Socket插件认证。具体参考https://mariadb.com/kb/en/library/authentication-plugin-unix-socket/

使用service mysql status查看mysql服务状态你会发现有这样一条警告。

[Warning] ‘user’ entry root@localhost’ has both a password and an authentication plugin specified. The password will be ignored.

也就是使用Unix Socke插件认证直接忽略密码,自然使用密码也就无效了。

##解决方法

虽然这是为了提高安全性,但有的地方我们必须使用密码认证登录,因此我们就要修改验证为密码的方式。直接在命令行输入 mysql 登录数据库。使用以下命令修改

use mysql;
update mysql.user set plugin='mysql_native_password' where User='root';
flush privileges;

posted @ 2021-08-05 12:01  局域网外  阅读(216)  评论(0编辑  收藏  举报