关于php7.3.3 连接mysql8 出现 The server requested authentication method unknown to the client
主要原因 是因为 mysql 8 升级了密码的验证方式 caching_sha2_password, 之前一直是mysql_native_password方式
不过 我很好奇 为什么php都升级到7.3.3了,为什么还不支持caching_sha2_password ,无语。
解决办法:
1.找到mysql的配置文件my.cnf,我的配置文件位置在 /usr/local/etc/my.cnf (请自行找到自己的电脑的配置文件地址)。
2.在 [mysqld]下加入 default-authentication-plugin=mysql_native_password 一行
3.重启mysql(我的重启命令为mysql.server restart)
4.进入mysql 修改登入mysql用户的登录验证方式
ALTER USER
'root'
@
'localhost'
IDENTIFIED WITH mysql_native_password BY
'root'
;
5. 重新回到php尝试连接mysql
获得的经验:如果知道要连接的mysql版本为8以及8以上 ,最好在创建用户的时候加上
CREATE USER 'root123'@'localhost' IDENTIFIED WITH mysql_native_password BY 'root123';
来指定验证方式。