学无先后,达者为师

网站首页 PHP其他 正文

php7链接数据库报错The server requested authentication method unknown to the client

作者:沉、睡 更新时间: 2022-02-01 PHP其他

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

原文链接:https://blog.csdn.net/zz975896590/article/details/119991162

栏目分类
最近更新