PHP连接mysql8.0出错“SQLSTATE[HY000] [2054] The server requested authentication method unknow.....

PHP连接mysql8.0出错“SQLSTATE[HY000] [2054] The server requested authentication method unknow.....

这个错可能是mysql默认使用 caching_sha2_password
作为默认的身份验证插件,而不再是 mysql_native_password
,但是客户端暂时不支持这个插件导致的。

解决方法一:修改MySQL全局配置文件

编辑 my.cnf
文件,更改默认的身份认证插件。

$ vi /etc/my.cnf

在 [mysqld]
中添加下边的代码

default_authentication_plugin=mysql_native_password

然后重启mysql

$ service mysqld restart