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?
SQLSTATE[HY000] [2054] Server sent charset unknown to the client. Please, report to the developers
What version of PHP are you using?
According to PHP's bugtracker, this should be fixed as of 7.0.19, 7.1.5, and 7.2.0.
https://bugs.php.net/bug.php?id=74461
Some answers recommended changing the server charset back to utf8
from utf8mb4
, but that is a bad idea. utf8
doesn't support the full range of valid unicode characters, so trying to save a string that contains certain characters (like some sets of emoji) will cause a database error. It is much better to simply upgrade PHP to a more recent version.
Failed to connect to MySQL: Server sent charset unknown to the client. Please, report to the developers - SamplePage.php
Turns out all this work on changing the charset and making sure the charset in the database was set properly was just a dependency on another problem, which was the mysqli
extension was not properly installed and enabled. I also upgrade the php version to 7.2, which also may have fixed the issue but I am not entirely sure. Maybe someone can verify what the fix was based on what I had done?
phpMyAdmin errors logging in
Try below things
Set in my.cnf
[client]
default-character-set=utf8
[mysql]
default-character-set=utf8
[mysqld]
collation-server = utf8_unicode_ci
character-set-server = utf8
Also if you have my.ini both work successful with me.
Related Topics
What Are the Disadvantages of Using Persistent Connection in Pdo
How to Make Pdf File Downloadable in HTML Link
Are Arrays in PHP Copied as Value or as Reference to New Variables, and When Passed to Functions
How to Enable Curl in PHP/Xampp
Post Request in Laravel - Error - 419 Sorry, Your Session/ 419 Your Page Has Expired
PHP Warning: PHP Startup: How to Load Dynamic Library
PHP Function to Make Slug (Url String)
PHP/MySQL Insert Row Then Get 'Id'
Get Table Column Names in MySQL
Show Values from a MySQL Database Table Inside a HTML Table on a Webpage
How to Add/Remove Pkcs7 Padding from an Aes Encrypted String
How to Get Directory Size in PHP
How to Extend a Class Using More Than 1 Class in PHP
I Have an Array of Integers, How to Use Each One in a MySQL Query (In PHP)