2014-01-22 80 views
0

完全支持utf8所以我設置的mysql:phpMyAdmin的顯示字符怪異(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) 

現在,我正確地存儲和獲取(和json_encode)utf8字符在我的web應用程序與我的mysql查詢,但我有一個問題與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)很奇怪,因爲你可以看到一切正常utf8 b)我想避免每次運行該查詢

這是一個phpmyadmin唯一的問題或我的設置一般的數據編碼問題?無論哪種方式,我該如何解決這個問題?最好只是配置文件設置,而不必每次都運行SET NAMES utf8查詢。

在此先感謝。

+0

[_How的可能重複顯示UTF -8字符在phpMyAdmin?_](http://stackoverflow.com/questions/4777900/how-to-display-utf-8-characters-in-phpmyadmin)。 –

+1

您忽略了最重要的部分:您的* table *排序規則和您的實際* client *編碼。其他一切都是默認值。如果您已經從PHP插入數據而沒有SET NAMES utf8(儘管這不是推薦的方法),但現在可能已經損壞了。 –

+0

[UTF-8一路通過]可能的重複(http://stackoverflow.com/questions/279170/utf-8-all-the-way-through) –

回答

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"}