phpmyadmin显示奇怪的字符(utf8)

时间:2014-01-22 09:23:54

标签: php mysql utf-8 phpmyadmin

所以我设置了mysql以获得完整的utf8支持:

的my.cnf:

[mysqld]
character_set_client=utf8
character-set-server=utf8
collation_server=utf8_general_ci

mysql> show variables like "char%";
+--------------------------+----------------------------+
| Variable_name            | Value                      |
+--------------------------+----------------------------+
| character_set_client     | utf8                       |
| character_set_connection | utf8                       |
| character_set_database   | utf8                       |
| character_set_filesystem | binary                     |
| character_set_results    | utf8                       |
| character_set_server     | utf8                       |
| character_set_system     | utf8                       |
| character_sets_dir       | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+
8 rows in set (0.00 sec)

mysql> show variables like "coll%";
+----------------------+-----------------+
| Variable_name        | Value           |
+----------------------+-----------------+
| collation_connection | utf8_general_ci |
| collation_database   | utf8_general_ci |
| collation_server     | utf8_general_ci |
+----------------------+-----------------+
3 rows in set (0.00 sec)

现在,我正确地使用我的mysql查询在我的网络应用程序中存储并获取(和json_encode)utf8字符,但我遇到了phpmyadmin的问题。问题是phpmyadmin将这些国际字符显示为乱码文本。

έλεος

sadaa

只是为了澄清事情,我说的是新数据,尚未存储可能已损坏的数据。

phpmyadmin的会话变量是:

show variables like "char%";
Variable_name   Value   
character_set_client    utf8mb4
character_set_connection    utf8mb4
character_set_database  utf8
character_set_filesystem    binary
character_set_results   utf8mb4
character_set_server    utf8
character_set_system    utf8
character_sets_dir  /usr/share/mysql/charsets/

show variables like "coll%" 
Variable_name   Value   
collation_connection    utf8mb4_general_ci
collation_database  utf8_general_ci
collation_server    utf8_general_ci

到目前为止我发现国际utf8字符在phpmyadmin中正确显示而不是乱码文本的唯一方法是运行

SET NAMES utf8

每次客户端应用程序(php)查询之前: a)很奇怪,因为你可以看到一切都是正确的 b)我想避免每次都运行该查询

这是一个phpmyadmin唯一的问题或我的设置的一般数据编码问题?无论哪种方式,我该如何解决这个问题?最好只配置文件设置,而不必每次都运行SET NAMES utf8查询。

提前感谢。

1 个答案:

答案 0 :(得分:0)

回答我自己的问题。

似乎这不是一个phpmyadmin问题,而是一般的编码问题。

问题是我没有设置我的客户端连接字符集。

这是我从php文件中显示变量时得到的结果:

{"Variable_name":"character_set_client","Value":"latin1"}
{"Variable_name":"character_set_connection","Value":"latin1"}
{"Variable_name":"character_set_database","Value":"utf8"}
{"Variable_name":"character_set_filesystem","Value":"binary"}
{"Variable_name":"character_set_results","Value":"latin1"}
{"Variable_name":"character_set_server","Value":"utf8"}
{"Variable_name":"character_set_system","Value":"utf8"}
{"Variable_name":"character_sets_dir","Value":"\/usr\/share\/mysql\/charsets\/"}



{"Variable_name":"collation_connection","Value":"latin1_swedish_ci"}
{"Variable_name":"collation_database","Value":"utf8_general_ci"}
{"Variable_name":"collation_server","Value":"utf8_general_ci"}

最初我尝试添加my.cnf

[client]
default-character-set=utf8

它不工作。

因此解决方案是添加:

charset=UTF8

在PDO初始化

所以在那之后我得到了正确的变量值:

{"Variable_name":"character_set_client","Value":"utf8"}
{"Variable_name":"character_set_connection","Value":"utf8"}
{"Variable_name":"character_set_database","Value":"utf8"}
{"Variable_name":"character_set_filesystem","Value":"binary"}
{"Variable_name":"character_set_results","Value":"utf8"}
{"Variable_name":"character_set_server","Value":"utf8"}
{"Variable_name":"character_set_system","Value":"utf8"}
{"Variable_name":"character_sets_dir","Value":"\/usr\/share\/mysql\/charsets\/"}



{"Variable_name":"collation_connection","Value":"utf8_general_ci"}
{"Variable_name":"collation_database","Value":"utf8_general_ci"}
{"Variable_name":"collation_server","Value":"utf8_general_ci"}