当前位置:
首页 >
行业知识 >
MySQL错误解决办法 SQLSTATE[HY000] [2054] The server requested authentication method unknown to the client
行业知识
MySQL错误解决办法 SQLSTATE[HY000] [2054] The server requested authentication method unknown to the client
2026-11-30 01:53:34
来源:互联网转载
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.cnf
在[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
- 操作完毕后,重启MYSQL服务。
- 查看
- 修改用户密码
上一篇:金融官网一站式在线服务体验专区
下一篇:怎么收件服务器端口?