PDO :: __ construct():服务器向客户端发送了未知的字符集(255).请向开发商报告 [英] PDO::__construct(): Server sent charset (255) unknown to the client. Please, report to the developers
问题描述
我正在尝试从Symfony 3应用程序连接到MySQL数据库.但是,当尝试从Symfony控制台命令创建MySQL模式时,出现以下错误:PDO::__construct(): Server sent charset (255) unknown to the client. Please, report to the developers
I'm trying to connect to a MySQL database from Symfony 3 application. But when trying to create MySQL schema from a Symfony console command I get this error: PDO::__construct(): Server sent charset (255) unknown to the client. Please, report to the developers
PHP和MySQL都在Docker容器中运行.
Both PHP and MySQL are running in Docker containers.
MySQL版本:8.0.1
PHP版本:7.1.3
驱动程序:pdo_mysql
字符集:UTF8
dsn:"mysql:host=mysql;dbname=database;charset=UTF8;"
有什么想法吗?
推荐答案
MySQL 8将默认字符集更改为utf8mb4.但是有些客户不知道这个字符集.因此,当服务器向客户端报告其默认字符集,而客户端不知道服务器的含义时,则会引发此错误.
MySQL 8 changed the default charset to utf8mb4. But some clients don't know this charset. Hence when the server reports its default charset to the client, and the client doesn't know what the server means, it throws this error.
另请参见 https://bugs.mysql.com/bug.php?id= 71606
该错误是针对MySQL Connector/C ++的,因此它影响的不仅仅是PHP.
That bug is against the MySQL Connector/C++ so it's affecting more than just PHP.
好的-我通过将字符集更改为utf8使其能够与未升级的客户端兼容来使其正常工作.我将此添加到/etc/my.cnf并重新启动mysqld:
Okay—I got it to work by changing the character set to utf8, to be compatible with non-upgraded clients. I added this to /etc/my.cnf and restarted mysqld:
[client]
default-character-set=utf8
[mysql]
default-character-set=utf8
[mysqld]
collation-server = utf8_unicode_ci
character-set-server = utf8
I found these settings in an answer from 2010: Change MySQL default character set to UTF-8 in my.cnf?
这篇关于PDO :: __ construct():服务器向客户端发送了未知的字符集(255).请向开发商报告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!