php7废弃了MySQL,关于mysql8.0版本和PHP7不兼容的问题
新安装了mysql8.0版本。当PHP连接数据库的时候,会出现一个情况就是连接数据库失败,一般来说会出现以下两种情况:
1.报错:PDO::__construct(): Server sent charset (255) unknown to the client. Please, report to the developers
2.报错:PDO::__construct(): The server requested authentication method unknown to the client [caching_sha2_password]
第一种出现这种情况主要是mysql8.0默认是utfmb4的格式,PHP默认的是UTF8格式,因此需要将mysql8.0默认格式设置为utf8,
就需要修改my.cnf,下面是我设置的my.cnf
[client]
default-character-set=utf8
[mysql]
default-character-set=utf8
[mysqld]
collation-server = utf8_unicode_ci
init-connect='SET NAMES utf8'
character-set-server = utf8
第二种情况,那是因为用户身份认证的加密方式不兼容导致的,mysql8.0中默认方式为caching_sha2_password,引起老版本兼容性问题,老版本加密方式为mysql_native_password。
新建用老版加密方式初始化密码的用户即可:
CREATEUSERusername@localhostidentifiedwithmysql_native_passwordby'password';
然后在my.cnf中添加一行:default_authentication_plugin=mysql_native_password;
总结
以上是生活随笔为你收集整理的php7废弃了MySQL,关于mysql8.0版本和PHP7不兼容的问题的全部内容,希望文章能够帮你解决所遇到的问题。
- 上一篇: matlab读取表格读成mat文件,MA
- 下一篇: oracle测试表什么名字,Oracle