报错:
SQLSTATE[HY000] [2054] Server sent charset unknown to the client. Please, report to the developers
解决:
在D:\phpStudy\PHPTutorial\MySQL下的my.ini中的mysqld下加如下语句
character-set-server = utf8mb4
collation-server = utf8mb4_unicode_ci
图1重启PHPstudy,之后报错:
SQLSTATE[HY000] [2054] The server requested authentication method unknown to the client
解决:
bin目录下连接数据库,
mysql -u root -p
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password by 'root';
注:by后面是数据库密码,自己设置
刷新权限
flush privileges;
然后再my.ini中的mysqld下面加
default_authentication_plugin = mysql_native_password 如图1所示
重启PHPstudy,连接成功
参考来源:
1.ThinkPHP 3.2 连接MySQL 8 出现的utf8mb4字符集错误
ThinkPHP 3.2 连接MySQL 8 出现的utf8mb4字符集错误
2018-9-20 03:48 PM
ThinkPHP 3.2 连接MySQL 8时报如下错误:
SQLSTATE[HY000] [2054] Server sent charset unknown to the client. Please, report to the developers
网上查询得知MySQL 8 默认字符集为utf8mb4,给出的解决方法都是设置MySQL的默认字符集为老版本的utf8,然而其实只需要在MySQL配置文件中[mysqld]下加这两行
character-set-server = utf8mb4
collation-server = utf8mb4_unicode_ci
同时在TP配置文件中的数据库连接信息中指明字符集utf8即可
'DB_CHARSET'=> 'utf8', // 字符集
如果又出现这样的报错:
QLSTATE[HY000] [2054] The server requested authentication method unknown to the client
是因为MySQL8中用户的认证类型(Authentication type)默认为cacheing sha2 password导致的错误,需要修改用户权限认证方式为5.x的认证方式
alter user 'root'@'%' identified with mysql_native_password by '123456';
#刷新权限
flush privileges;
然后在MySQL配置文件中[mysqld]下加上
default_authentication_plugin=mysql_native_password
网友评论