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

Solution:1

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?

Solution:2

The accepted answer saved me (thanks, Bill!!!), but I ran into another related issue, just wanted to provide some details on my experience –

 

After upgrading to MySQL 8.0.11, I experienced the same problem as the OP when using PHP’s mysqli_connect() function. In my MySQL directory (in my case, usr/local/mysql), I created the my.cnf file, added the content in the accepted answer, then restarted the MySQL server. However, this produced a new error:

 

mysqli_connect(): The server requested authentication method unknown to the client [caching_sha2_password]

 

I added the line default_authentication_plugin = mysql_native_password, so my.cnf now looked like:

 

[client]

default-character-set=utf8

 

[mysql]

default-character-set=utf8

 

[mysqld]

collation-server = utf8_unicode_ci

character-set-server = utf8

default_authentication_plugin = mysql_native_password

and I was good to go!

 

For additional reference: https://github.com/laradock/laradock/issues/1392