php5.6 + mysql8.0 出现mysql连接失败的错误

The server requested authentication method unknown to the client

服务器请求的身份验证方法客户端未知

原因

发生这个问题的原因是在 mysql 8.0 以后,caching_sha2_password是默认的身份验证插件,而不是以往的mysql_native_password

解决方法:


在mysql目录里 找到 my.ini

后面加上一行(如果原来有default_authentication_plugin这个选项 就修改  没有就在后面添加)

# mysql密码验证方式 使其支持php5.6 或低版本的php
default_authentication_plugin=mysql_native_password

加上后  重启mysql即可解决