mysqlの文字セット統一設定の問題


最近1つのプロジェクトをして、過程の中でデータベースの文字化けしが発生して、phpmyadminの中からどのように設定するか分かりません.行きましょう!!文字セット設定が一致していないに違いないと思いますが、php符号化は正しいし、utf-8の文字セット設定を採用しているのでmysql文字セット設定の問題に違いありません.またphpmyadminで半日設定してもだめです.おばあちゃんの、いっそphpmyadminを使わないで、本当に骨が折れる!!
直接mysqlのコンソールを开いて、ハハはよくなって、下の操作があなた达に役に立つことを望んで、覚えて帰って、みんなはいっしょに进歩します!!!

  
  
  
  
  1. 、  MySQL  。  
  2.  
  3. mysql> show variables like '%char%';  
  4. +--------------------------+-------------------------------------+------  
  5. | Variable_name            | Value                               |......  
  6. +--------------------------+-------------------------------------+------  
  7. | character_set_client     | utf8                                |......   --   
  8. | character_set_connection | utf8                                |......  
  9. | character_set_database   | utf8                                |......   --   
  10. | character_set_filesystem | binary                              |......  
  11. | character_set_results    | utf8                                |......  
  12. | character_set_server     | utf8                                |......   --   
  13. | character_set_system     | utf8                                |......  
  14. | character_sets_dir       | D:\MySQL Server 5.0\share\charsets\ |......  
  15. +--------------------------+-------------------------------------+------  
  16. 、  MySQL  (table)  。  
  17.  
  18. mysql> show table status from sqlstudy_db like '%countries%';  
  19. +-----------+--------+---------+------------+------+-----------------+------  
  20. | Name      | Engine | Version | Row_format | Rows | Collation       |......  
  21. +-----------+--------+---------+------------+------+-----------------+------  
  22. | countries | InnoDB |      10 | Compact    |   11 | utf8_general_ci |......  
  23. +-----------+--------+---------+------------+------+-----------------+------  
  24. 、  MySQL  (column) 。  
  25.  
  26. mysql> show full columns from countries;  
  27. +----------------------+-------------+-----------------+--------  
  28. | Field                | Type        | Collation       | .......  
  29. +----------------------+-------------+-----------------+--------  
  30. | countries_id         | int(11)     | NULL            | .......  
  31. | countries_name       | varchar(64) | utf8_general_ci | .......  
  32. | countries_iso_code_2 | char(2)     | utf8_general_ci | .......  
  33. | countries_iso_code_3 | char(3)     | utf8_general_ci | .......  
  34. | address_format_id    | int(11)     | NULL            | .......  
  35. +----------------------+-------------+-----------------+--------  
  36. 、  MySQL  。  
  37.  
  38. mysql> show charset;  
  39. mysql> show char set;  
  40. +----------+-----------------------------+---------------------+--------+  
  41. | Charset | Description                 | Default collation   | Maxlen |  
  42. +----------+-----------------------------+---------------------+--------+  
  43. | big5     | Big5 Traditional Chinese    | big5_chinese_ci     |      2 |  
  44. | dec8     | DEC West European           | dec8_swedish_ci     |      1 |  
  45. | cp850    | DOS West European           | cp850_general_ci    |      1 |  
  46. | hp8      | HP West European            | hp8_english_ci      |      1 |  
  47. | koi8r    | KOI8-R Relcom Russian       | koi8r_general_ci    |      1 |  
  48. | latin1   | cp1252 West European        | latin1_swedish_ci   |      1 |  
  49. | latin2   | ISO 8859-2 Central European | latin2_general_ci   |      1 |  
  50. | swe7     | 7bit Swedish                | swe7_swedish_ci     |      1 |  
  51. | ascii    | US ASCII                    | ascii_general_ci    |      1 |  
  52. | ujis     | EUC-JP Japanese             | ujis_japanese_ci    |      3 |  
  53. | sjis     | Shift-JIS Japanese          | sjis_japanese_ci    |      2 |  
  54. | hebrew   | ISO 8859-8 Hebrew           | hebrew_general_ci   |      1 |  
  55. | tis620   | TIS620 Thai                 | tis620_thai_ci      |      1 |  
  56. | euckr    | EUC-KR Korean               | euckr_korean_ci     |      2 |  
  57. | koi8u    | KOI8-U Ukrainian            | koi8u_general_ci    |      1 |  
  58. | gb2312   | GB2312 Simplified Chinese   | gb2312_chinese_ci   |      2 |  
  59. | greek    | ISO 8859-7 Greek            | greek_general_ci    |      1 |  
  60. | cp1250   | Windows Central European    | cp1250_general_ci   |      1 |  
  61. | gbk      | GBK Simplified Chinese      | gbk_chinese_ci      |      2 |  
  62. | latin5   | ISO 8859-9 Turkish          | latin5_turkish_ci   |      1 |  
  63. | armscii8 | ARMSCII-8 Armenian          | armscii8_general_ci |      1 |  
  64. | utf8     | UTF-8 Unicode               | utf8_general_ci     |      3 |  
  65. | ucs2     | UCS-2 Unicode               | ucs2_general_ci     |      2 |  
  66. | cp866    | DOS Russian                 | cp866_general_ci    |      1 |  
  67. | keybcs2 | DOS Kamenicky Czech-Slovak | keybcs2_general_ci |      1 |  
  68. | macce    | Mac Central European        | macce_general_ci    |      1 |  
  69. | macroman | Mac West European           | macroman_general_ci |      1 |  
  70. | cp852    | DOS Central European        | cp852_general_ci    |      1 |  
  71. | latin7   | ISO 8859-13 Baltic          | latin7_general_ci   |      1 |  
  72. | cp1251   | Windows Cyrillic            | cp1251_general_ci   |      1 |  
  73. | cp1256   | Windows Arabic              | cp1256_general_ci   |      1 |  
  74. | cp1257   | Windows Baltic              | cp1257_general_ci   |      1 |  
  75. | binary   | Binary pseudo charset       | binary              |      1 |  
  76. | geostd8 | GEOSTD8 Georgian            | geostd8_general_ci |      1 |  
  77. | cp932    | SJIS for Windows Japanese   | cp932_japanese_ci   |      2 |  
  78. | eucjpms | UJIS for Windows Japanese   | eucjpms_japanese_ci |      3 |  
  79. +----------+-----------------------------+---------------------+--------+  
  80.  MySQL  ,  Windows & Linux。  
  81.  
  82.    
  83.  
  84. Liunx MySQL :  
  85. 1. MySQL cnf  
  86. find / -iname '*.cnf' -print  
  87.  
  88. /usr/share/mysql/my-innodb-heavy-4G.cnf  
  89. /usr/share/mysql/my-large.cnf  
  90. /usr/share/mysql/my-small.cnf  
  91. /usr/share/mysql/my-medium.cnf  
  92. /usr/share/mysql/my-huge.cnf  
  93. /usr/share/texmf/web2c/texmf.cnf  
  94. /usr/share/texmf/web2c/mktex.cnf  
  95. /usr/share/texmf/web2c/fmtutil.cnf  
  96. /usr/share/texmf/tex/xmltex/xmltexfmtutil.cnf  
  97. /usr/share/texmf/tex/jadetex/jadefmtutil.cnf  
  98. /usr/share/doc/MySQL-server-community-5.1.22/my-innodb-heavy-4G.cnf  
  99. /usr/share/doc/MySQL-server-community-5.1.22/my-large.cnf  
  100. /usr/share/doc/MySQL-server-community-5.1.22/my-small.cnf  
  101. /usr/share/doc/MySQL-server-community-5.1.22/my-medium.cnf  
  102. /usr/share/doc/MySQL-server-community-5.1.22/my-huge.cnf  
  103.  
  104. 2.   small.cnf、my-medium.cnf、my-huge.cnf、my-innodb-heavy-4G.cnf /etc , my.cnf  
  105. cp /usr/share/mysql/my-medium.cnf /etc/my.cnf  
  106.  
  107. 3.  my.cnf  
  108. vi /etc/my.cnf  
  109. [client]  
  110. default-character-set=utf8 
  111. [mysqld]  
  112. default-character-set=utf8 
  113.  
  114. 4. MySQL  
  115. [root@bogon ~]# /etc/rc.d/init.d/mysql restart  
  116. Shutting down MySQL                                         [   ]  
  117. Starting MySQL.                                           [   ]  
  118. [root@bogon ~]# mysql -u root -p  
  119. Enter password:  
  120. Welcome to the MySQL monitor. Commands end with ; or \g.  
  121. Your MySQL connection id is 1  
  122. Server version: 5.1.22-rc-community-log MySQL Community Edition (GPL)  
  123. Type 'help;' or '\h' for help. Type '\c' to clear the buffer.  
  124.  
  125. :  
  126.  
  127.  
  128. mysql>use mydb  
  129. mysql>alter database mydb character set utf-8;  
  130.  
  131. mysql>create database mydb character set utf-8;  
  132.  
  133. :  
  134. /var/lib/mysql/mydb/db.opt  
  135. default-character-set=latin1 
  136. default-collation=latin1_swedish_ci 
  137.  
  138. default-character-set=utf8 
  139. default-collation=utf8_general_ci 
  140. MySQL:  
  141. [root@bogon ~]# /etc/rc.d/init.d/mysql restart  
  142.  
  143. MySQL :  
  144. mysql> set character_set_client=utf8;  
  145. Query OK, 0 rows affected (0.00 sec)  
  146. mysql> set character_set_connection=utf8;  
  147. Query OK, 0 rows affected (0.00 sec)  
  148. mysql> set character_set_database=utf8;  
  149. Query OK, 0 rows affected (0.00 sec)  
  150. mysql> set character_set_results=utf8;  
  151. Query OK, 0 rows affected (0.00 sec)  
  152. mysql> set character_set_server=utf8;  
  153. Query OK, 0 rows affected (0.00 sec)  
  154. mysql> set character_set_system=utf8;  
  155. Query OK, 0 rows affected (0.01 sec)  
  156. mysql> set collation_connection=utf8;  
  157. Query OK, 0 rows affected (0.01 sec)  
  158. mysql> set collation_database=utf8;  
  159. Query OK, 0 rows affected (0.01 sec)  
  160. mysql> set collation_server=utf8;  
  161. Query OK, 0 rows affected (0.01 sec)