Home >Database >Mysql Tutorial >MySQL PDO Connection Error: How to Resolve 'Server Sent Charset (255) Unknown to the Client'?

MySQL PDO Connection Error: How to Resolve 'Server Sent Charset (255) Unknown to the Client'?

Linda Hamilton
Linda HamiltonOriginal
2024-12-23 07:51:32620browse

MySQL PDO Connection Error: How to Resolve

Charset Mismatch Error: Server Sent Unknown Charset (255)

Attempting to connect to a MySQL database from Symfony 3 using PDO results in the following error: PDO::__construct(): Server sent charset (255) unknown to the client. Please, report to the developers. This error can occur due to a charset mismatch between the server and the client.

Cause

In MySQL 8, the default charset has changed to utf8mb4. However, some clients, such as PDO, may not recognize this charset. When the server sends its default charset to the client, and the client does not recognize it, the error is thrown.

Solution

The recommended solution is to upgrade the client software to a version that supports the utf8mb4 charset. However, until an upgrade is possible, a workaround exists:

Workaround

Change the server's character set to utf8 to be compatible with non-upgraded clients. To do this, add the following settings to the /etc/my.cnf file and restart the MySQL server:

[client]
default-character-set=utf8

[mysql]
default-character-set=utf8


[mysqld]
collation-server = utf8_unicode_ci
character-set-server = utf8

The above is the detailed content of MySQL PDO Connection Error: How to Resolve 'Server Sent Charset (255) Unknown to the Client'?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn