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。
在[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)
https://www.8a.hk/index.php/news/content/3993.html