标题有点罗嗦,目前出现的问题如下: 当以非root身份登录数据库时,会报错

mysql -u root -p
Enter password:
ERROR 1698 (28000): Access denied for user 'root'@'localhost'

而使用root身份访问就没有问题 问题探究 查看root用户使用的认证插件:

mysql> select user,plugin from user where user = 'root';
+------+-------------+
| user | plugin      |
+------+-------------+
| root | auth_socket |
+------+-------------+
1 row in set (0.00 sec)

MySQL使用的auth_socket是通过Unix套接字进行连接认证[1]

因此可以将认证插件改为 mysql_native_password 解决方法

ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'new_password';
FLUSH PRIVILEGES;

另请参阅 [1] https://dev.mysql.com/doc/refman/8.0/en/socket-pluggable-authentication.html [2] https://mariadb.com/kb/en/authentication-plugin-unix-socket/

03-27 07:59