我正在尝试从 phpMyAdmin 连接到 MySQL 数据库.但是当我输入用户名和密码时,我收到两条错误消息:
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
我使用的是 MySQL 8.0.11 和 phpMyAdmin 4.8.2
I'm using MySQL 8.0.11 and phpMyAdmin 4.8.2
我找到了一个类似问题的答案:PDO::__construct():服务器发送客户端未知的字符集 (255).请向开发者报告
I found this answer for a similar problem: PDO::__construct(): Server sent charset (255) unknown to the client. Please, report to the developers
这里是重要的部分:MySQL 8 将默认字符集更改为 utfmb4.但有些客户端不知道这个字符集.因此当服务器向客户端报告其默认字符集时,客户端不知道是什么服务器的意思是,它抛出这个错误."
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."
给出的解决方案是通过在/etc/my.cnf中添加几行并重新启动mysqld将默认字符集改回utf8.
The solution given is to change the default charset back to utf8 by adding a few lines to /etc/my.cnf and restart mysqld.
我的问题是/etc/my.cnf 在我的文件中不存在任何地方,所以我无法更改那里的默认字符集.我看过的所有其他地方最终都引用了/my.cnf 或引用了旧版本.
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.
那么,对于 MySQL 8,如何在没有/etc/my.cnf 的情况下将默认字符集更改为 utf8?
So, how do I change the default charset to utf8 without a /etc/my.cnf for MySQL 8?
澄清答案:
在您的 /etc/
文件夹中创建一个名为 my.cnf
的文件.
Create a file called my.cnf
in your /etc/
folder.
现在将以下文本添加到/etc/my.cnf
:
Now add the following text to /etc/my.cnf
:
[客户]
默认字符集=utf8
[client]
default-character-set=utf8
[mysql]
默认字符集=utf8
[mysql]
default-character-set=utf8
[mysqld]
整理服务器 = utf8_unicode_ci
字符集服务器 = utf8
default_authentication_plugin = mysql_native_password
[mysqld]
collation-server = utf8_unicode_ci
character-set-server = utf8
default_authentication_plugin = mysql_native_password
最后重启mysql,一切正常!如果仍有问题,请尝试将 PHP 升级到更高版本.
Finally, restart mysql and all should be well! If you still have an issue, try upgrading PHP to a later version.
这篇关于“服务器发送客户端未知的字符集(255)"将 MySQL 字符集设置为 utf8 w/o/etc/my.cnf?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!