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

Fatal error: Uncaught PDOException: SQLSTATE[HY000] [2054] The server requested authentication method unknown to the client [caching_sha2_password] in /usr/local/nginx/html/mysql.php:3 Stack trace: #0 /usr/local/nginx/html/mysql.php(3): PDO->__construct('mysql:host=127....', 'root', Object(SensitiveParameterValue)) #1 {main} thrown in /usr/local/nginx/html/mysql.php on line 3

错误原因

错误原因是对 MySQL 进行的版本升级,MySQL8中用户的认证类型(Authentication type)默认为 caching_sha2_password 导致的错误,需要修改用户权限认证方式为 mysql_native_password

解决办法

1.数据库降级,退回以前版本

2. 改为 mysql_native_password 认证方式

  • 修改mysql配置文件/etc/my.***f

[mysqld]节点下如下内容,如果以及存在default_authentication_plugin节点,覆盖即可。

[mysqld]
...
default_authentication_plugin=mysql_native_password
...

由于更改了认证方式,所以要更改链接MYSQL用户的密码。以下以root为例

# mysql -u root -p
  • 修改用户密码
mysql> alter user 'root'@'%' identified with mysql_native_password by '123456';
mysql> flush privileges;
  • 查看
mysql> use mysql;
mysql> select host,user,plugin from user;
+-----------+------------------+-----------------------+
| host      | user             | plugin                |
+-----------+------------------+-----------------------+
| %         | root             | mysql_native_password |
| localhost | mysql.infoschema | caching_sha2_password |
| localhost | mysql.session    | caching_sha2_password |
| localhost | mysql.sys        | caching_sha2_password |
+-----------+------------------+-----------------------+
4 rows in set (0.00 sec)

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

参考

https://www.8a.hk/index.php/news/content/3993.html

转载请说明出处内容投诉
CSS教程_站长资源网 » MySQL错误解决办法 SQLSTATE[HY000] [2054] The server requested authentication method unknown to the client

发表评论

欢迎 访客 发表评论

一个令你着迷的主题!

查看演示 官网购买