“Server sent charset (255) unknown to the client” Set MySQL charset to utf8 w/o /etc/my.cnf?

天涯浪子 提交于 2020-01-21 07:22:30

问题


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?


回答1:


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.




回答2:


Reinstall MySQL 8 and choose Second Method "Use Legacy Authentication Method(Retain MySQL 5.x compatibility)" of Authentication while installing.



来源:https://stackoverflow.com/questions/51051440/server-sent-charset-255-unknown-to-the-client-set-mysql-charset-to-utf8-w-o

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!