Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"Server sent charset (255) unknown to the client" Set MySQL charset to utf8 w/o /etc/my.cnf? [duplicate]

Tags:

php

mysql

utf-8

pdo

I'm trying to connect to a MySQL database from phpMyAdmin. But when I put in username and password I get two error messages saying:

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

mysqli_real_connect(): (HY000/2054): Server sent charset unknown to the client. Please, report to the developers

I'm using MySQL 8.0.11 and phpMyAdmin 4.8.2

I found this answer for a similar problem: PDO::__construct(): Server sent charset (255) unknown to the client. Please, report to the developers

Here is the important part: "MySQL 8 changed the default charset to utfmb4. 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."

The solution given is to change the default charset back to utf8 by adding a few lines to /etc/my.cnf and restart mysqld.

My problem is that /etc/my.cnf doesn't exist anywhere in my files so I can't change the default charset there. All of the other places I've looked end up referring to /my.cnf or reference older versions.

So, how do I change the default charset to utf8 without a /etc/my.cnf for MySQL 8?

like image 307
X Mac Avatar asked Jun 26 '18 21:06

X Mac


2 Answers

To clarify the answer:

  1. Create a file called my.cnf in your /etc/ folder.

  2. Now add the following text to /etc/my.cnf:

    [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

Finally, restart mysql and all should be well! If you still have an issue, try upgrading PHP to a later version.

like image 132
Oli C Avatar answered Oct 23 '22 17:10

Oli C


I had this problem also. The issue was because I was running an old version of PHP (5.6) and once I upgraded to PHP 7.4 the errors went away.

This was on Amazon Linux 2 for me and the command to upgrade was:

amazon-linux-extras install php7.4

I've found that many versions of RedHat/CentOS come with PHP 5.6 by default and the easiest way I've been able to upgrade them to the latest PHP is by using remi's repo here (https://rpms.remirepo.net/)

like image 45
jbrahy Avatar answered Oct 23 '22 19:10

jbrahy