异常信息
SQLSTATE[HY000] [2054] The server requested authentication method unknown to the client[/app/thinkphp/library/think/db/Connection.php:295]
![解决MYSQL连接异常:SQLSTATE[HY000] [2054]-第0张图片](https://www.mlplus.net/wp-content/uploads/2022/07/20220728180317.png)
原因
MySQL8中用户的认证类型(Authentication type)默认为cacheing sha2 password导致的错误,需要修改用户权限认证方式为mysql_native_password。
我这个错误就是因为数据库升级导致的。
解决办法
- 数据库降级,退回以前版本
- 改为
mysql_native_password认证方式
数据库退回以前的版本,这里不进行操作了。下面只针对认证方式改回mysql_native_password的方式。
修改mysql配置文件my.cnf
vi /etc/my.cnf
在[mysqld]节点下如下内容,如果以及存在default_authentication_plugin节点,覆盖即可。
default_authentication_plugin=mysql_native_password
![解决MYSQL连接异常:SQLSTATE[HY000] [2054]-第1张图片](https://www.mlplus.net/wp-content/uploads/2022/07/20220728180715.png)
由于更改了认证方式,所以要更改链接MYSQL用户的密码。以下以root为例
mysql -u root -p
执行以下代码完成链接MYSQL的用户密码的修改。
alter user '用户'@'%' identified with mysql_native_password by '密码';
flush privileges;
以root用户为例
alter user 'root'@'%' identified with mysql_native_password by '123456';
flush privileges;
操作完毕后,重启MYSQL服务。
支付宝扫码打赏
微信打赏