排行榜

MySQL:SQLSTATE[HY000] [2054] The server requested authentication method unknown to the client错误的解决办法

本文阅读 2 分钟
首页 运维中心 正文
广告


背景

MySQL报错:


SQLSTATE[HY000] [2054] The server requested authentication method unknown to the client

CDbException: CDbConnection failed to open the DB connection. in D:\work\php\framework\db\CDbConnection.php:405


image.png


错误原因

错误原因是对 MySQL 进行的版本升级,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

如果没有效果的话,可能是default_authentication_plugin关键字弃用了,可以使用authentication_policy替换

authentication_policy=mysql_native_password


image.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 'root';

flush privileges;


操作完毕后,重启MYSQL服务。

本文经授权后发布,本文观点不代表立场,文章出自:https://www.02405.com/archives/9059
让win11右键默认显示更多,恢复win10风格
« 上一篇 05-21
广告

作者信息

广告

动态快讯

热门文章

广告

标签TAG