PDO::__construct(): Server sent charset (255) unknown to the client. Please, report to the developers
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?
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
My case was that I was using RDS (MySQL db verion 8) of AWS and was connecting my application through EC2 (my php code 5.6 was in EC2).
Here in this case since it is RDS there is no my.cnf the parameters are maintained by PARAMETER Group of AWS. Refer: https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/USER_WorkingWithParamGroups.html
So what I did was:
-
Created a new Parameter group and then edited them.
-
Searched all character-set parameters. These are blank by default. edit them individually and select utf8 from drop down list.
character_set_client, character_set_connection, character_set_database, character_set_server
- SAVE
And then most important, Rebooted RDS instance.
This has solved my problem and connection from php5.6 to mysql 8.x was working great.
Please view this image for better understanding.
Works for me >
the environment:
localhost
Windows 10
PHP 5.6.31
MYSQL 8
set:
default-character-set=utf8
on:
c:\programdata\mysql\mysql server 8.0\my.ini
- Not works on>
C:\Program Files\MySQL\MySQL Server 5.5\my.ini
Tools that helps:
C:\Program Files\MySQL\MySQL Server 8.0\bin>mysql -u root -p
mysql> show variables like 'char%';
mysql> show variables like 'collation%';
\m/