PDO::__construct(): Server sent charset (255) unknown to the client. Please, report to the developers(PDO::__construct():服务器向客户端发送未知字符集 (255).请向开发人员报告)
问题描述
我正在尝试从 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?
这篇关于PDO::__construct():服务器向客户端发送未知字符集 (255).请向开发人员报告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:PDO::__construct():服务器向客户端发送未知字符集 (255).请向开发人员报告


- 带有通配符的 Laravel 验证器 2021-01-01
- 没有作曲家的 PSR4 自动加载 2022-01-01
- Mod使用GET变量将子域重写为PHP 2021-01-01
- 如何定位 php.ini 文件 (xampp) 2022-01-01
- SoapClient 设置自定义 HTTP Header 2021-01-01
- Oracle 即时客户端 DYLD_LIBRARY_PATH 错误 2022-01-01
- Laravel 仓库 2022-01-01
- PHP Count 布尔数组中真值的数量 2021-01-01
- 从 PHP 中的输入表单获取日期 2022-01-01
- 正确分离 PHP 中的逻辑/样式 2021-01-01