php7链接数据库报错The server requested authentication method unknown to the client
主要原因 是因为 mysql 8.0 升级了密码的验证方式 cachingsha2password, 之前一直是mysqlnativepassword方式
解决办法:
1.找到mysql的配置文件my.cnf,我的配置文件位置在 /usr/local/etc/my.cnf (请自行找到自己的电脑的配置文件地址)。
2.在 [mysqld]下加入 default-authentication-plugin=mysqlnativepassword 一行
3.重启mysql(我的重启命令为mysql.server restart)
4.进入mysql 修改登入mysql用户的登录验证方式
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'root';
5.重新回到php尝试连接mysql