Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PDO::__construct(): Server sent charset (255) unknown to the client. Please, report to the developers

Tags:

php

mysql

pdo

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

Both PHP and MySQL are running in Docker containers.

MySQL version: 8.0.1

PHP version: 7.1.3

Driver: pdo_mysql

charset: UTF8

dsn: "mysql:host=mysql;dbname=database;charset=UTF8;"

Any ideas?

like image 685
Napas Avatar asked Apr 16 '17 12:04

Napas


1 Answers

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.

See also https://bugs.mysql.com/bug.php?id=71606

That bug is against the MySQL Connector/C++ so it's affecting more than just PHP.

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?

like image 77
Bill Karwin Avatar answered Sep 21 '22 14:09

Bill Karwin