問題描述
我正在嘗試從 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模板網!