在 php 7.3.0 里,配置连接 MySQL 8.0 版本数据库的时候,会有错误
以下是错误信息:
Error: Unable to connect to MySQL.
Debugging errno: 2054
Debugging error: The server requested authentication method unknown to the client
查资料后发现,是 MySQL 8.0 的默认身份认证插件是 caching_sha2_password
更改成 mysql_native_password 即可
方式一:
更改mysql的配置文件(重启生效)
[mysqld]
default_authentication_plugin=mysql_native_password
注意,这样修改的是默认的身份认证插件
已经创建的账户的身份认证插件还是 caching_sha2_password
所以,要么删掉再创建账户,要么使用方式二修改
方式二:
mysql的repl执行以下语句:
ALTER USER user
IDENTIFIED WITH mysql_native_password
BY 'password';
如:
alter 'root'@'localhost' identified with mysql_native_password by '123456';