PDO::__construct():服务器向客户端发送未知字符集 (255).请向开发人员报告

2022-01-30 00:00:00 php mysql pdo

我正在尝试从 Symfony 3 应用程序连接到 MySQL 数据库.但是当尝试从 Symfony 控制台命令创建 MySQL 模式时,我收到此错误:PDO::__construct(): Server sent charset (255) unknown to the client.请向开发者报告

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 连接器/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

我在 2010 年的回答中找到了这些设置:在 my.cnf 中将 MySQL 默认字符集更改为 UTF-8?

I found these settings in an answer from 2010: Change MySQL default character set to UTF-8 in my.cnf?

相关文章