近日發(fā)現(xiàn)很多人為
MySQL中文亂碼問(wèn)題所困擾。于是就這個(gè)問(wèn)題做一下淺析。不正確的地方希望大家指正
/*
來(lái)源
PHPfans
網(wǎng)址:http://www.phpfans.net
*/
亂碼產(chǎn)生原因mysql字符編碼是版本4.1引入的,支持多國(guó)語(yǔ)言,而且一些特性已經(jīng)超過(guò)了其他的
數(shù)據(jù)庫(kù)系統(tǒng)。
我們可以在MySQL Command Line Client 下輸入如下命令查看mysql的字符集
mysql> SHOW CHARACTER SET;
+----------+-----------------------------+---------------------+--------+
| Charset??| Description? ?? ?? ?? ?? ???| Default collation? ?| Maxlen |
+----------+-----------------------------+---------------------+--------+
| big5? ???| Big5 Traditional Chinese? ? | big5_chinese_ci? ???| 2? ?? ?|
| dec8? ???| DEC West European? ?? ?? ???| dec8_swedish_ci? ???| 1? ?? ?|
| cp850? ? | DOS West European? ?? ?? ???| cp850_general_ci? ? | 1? ?? ?|
| hp8? ?? ?| HP West European? ?? ?? ?? ?| hp8_english_ci? ?? ?| 1? ?? ?|
| koi8r? ? | KOI8-R Relcom Russian? ?? ? | koi8r_general_ci? ? | 1? ?? ?|
| latin1? ?| cp1252 West European? ?? ???| latin1_swedish_ci? ?| 1? ?? ?|
| latin2? ?| ISO 8859-2 Central European | latin2_general_ci? ?| 1? ?? ?|
| swe7? ???| 7bit Swedish? ?? ?? ?? ?? ? | swe7_swedish_ci? ???| 1? ?? ?|
| ascii? ? | US ASCII? ?? ?? ?? ?? ?? ???| ascii_general_ci? ? | 1? ?? ?|
| ujis? ???| EUC-JP Japanese? ?? ?? ?? ? | ujis_japanese_ci? ? | 3? ?? ?|
| sjis? ???| Shift-JIS Japanese? ?? ?? ? | sjis_japanese_ci? ? | 2? ?? ?|
| hebrew? ?| ISO 8859-8 Hebrew? ?? ?? ???| hebrew_general_ci? ?| 1? ?? ?|
| tis620? ?| TIS620 Thai? ?? ?? ?? ?? ???| tis620_thai_ci? ?? ?| 1? ?? ?|
| euckr? ? | EUC-KR Korean? ?? ?? ?? ?? ?| euckr_korean_ci? ???| 2? ?? ?|
| koi8u? ? | KOI8-U Ukrainian? ?? ?? ?? ?| koi8u_general_ci? ? | 1? ?? ?|
| gb2312? ?| GB2312 Simplified Chinese? ?| gb2312_chinese_ci? ?| 2? ?? ?|
| greek? ? | ISO 8859-7 Greek? ?? ?? ?? ?| greek_general_ci? ? | 1? ?? ?|
| cp1250? ?| Windows Central European? ? | cp1250_general_ci? ?| 1? ?? ?|
| gbk? ?? ?| GBK Simplified Chinese? ?? ?| gbk_chinese_ci? ?? ?| 2? ?? ?|
| latin5? ?| ISO 8859-9 Turkish? ?? ?? ? | latin5_turkish_ci? ?| 1? ?? ?|
| armscii8 | ARMSCII-8 Armenian? ?? ?? ? | armscii8_general_ci | 1? ?? ?|
| utf8? ???| UTF-8 Unicode? ?? ?? ?? ?? ?| utf8_general_ci? ???| 3? ?? ?|
| ucs2? ???| UCS-2 Unicode? ?? ?? ?? ?? ?| ucs2_general_ci? ???| 2? ?? ?|
| cp866? ? | DOS Russian? ?? ?? ?? ?? ???| cp866_general_ci? ? | 1? ?? ?|
| keybcs2??| DOS Kamenicky Czech-Slovak??| keybcs2_general_ci??| 1? ?? ?|
| macce? ? | Mac Central European? ?? ???| macce_general_ci? ? | 1? ?? ?|
| macroman | Mac West European? ?? ?? ???| macroman_general_ci | 1? ?? ?|
| cp852? ? | DOS Central European? ?? ???| cp852_general_ci? ? | 1? ?? ?|
| latin7? ?| ISO 8859-13 Baltic? ?? ?? ? | latin7_general_ci? ?| 1? ?? ?|
| cp1251? ?| Windows Cyrillic? ?? ?? ?? ?| cp1251_general_ci? ?| 1? ?? ?|
| cp1256? ?| Windows Arabic? ?? ?? ?? ???| cp1256_general_ci? ?| 1? ?? ?|
| cp1257? ?| Windows Baltic? ?? ?? ?? ???| cp1257_general_ci? ?| 1? ?? ?|
| binary? ?| Binary pseudo charset? ?? ? | binary? ?? ?? ?? ???| 1? ?? ?|
| geostd8??| GEOSTD8 Georgian? ?? ?? ?? ?| geostd8_general_ci??| 1? ?? ?|
| cp932? ? | SJIS for Windows Japanese? ?| cp932_japanese_ci? ?| 2? ?? ?|
| eucjpms??| UJIS for Windows Japanese? ?| eucjpms_japanese_ci | 3? ?? ?|
+----------+-----------------------------+---------------------+--------+
36 rows in set (0.02 sec)
更多mysql的字符集知識(shí)可以參考
http://www.phpfans.net論壇的
http://www.phpfans.net/bbs/viewthread.php?tid=296&extra=page%3D1或者mysql官方的
http://dev.mysql.com/doc/refman/5.1/zh/charset.htmlMySQL 4.1的字符集支持(Character Set Support)有兩個(gè)方面:字符集(Character set)和排序方式(Collation)。對(duì)于字符集的支持細(xì)化到四個(gè)層次: 服務(wù)器(server),數(shù)據(jù)庫(kù)(database),數(shù)據(jù)表(table)和連接(connection)。
查看系統(tǒng)的字符集和排序方式的設(shè)定可以通過(guò)下面的兩條命令:
mysql> SHOW VARIABLES LIKE 'character_set_%';
+--------------------------+-------------------------------------------+
| Variable_name? ?? ?? ?? ?| Value? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ? |
+--------------------------+-------------------------------------------+
| character_set_client? ???| latin1? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?|
| character_set_
關(guān)鍵詞標(biāo)簽:及其,解決,原因,方法,
相關(guān)閱讀
常見(jiàn)的80004005錯(cuò)誤及其解決方法
華為p20升級(jí)鴻蒙系統(tǒng)方法-華為p20升級(jí)鴻蒙系統(tǒng)步驟
無(wú)線網(wǎng)絡(luò)互訪故障的現(xiàn)象及其應(yīng)對(duì)辦法
動(dòng)物大聯(lián)盟狂戰(zhàn)士最強(qiáng)裝備-動(dòng)物大聯(lián)盟狂戰(zhàn)士畢業(yè)裝備搭配
Linux系統(tǒng)進(jìn)程的幾個(gè)用戶ID及其轉(zhuǎn)換方法
無(wú)線路由器工作異常的三迷以及其三解
熱門(mén)文章
Xbox Game Pass
10款MySQL數(shù)據(jù)庫(kù)客戶端圖形界面管理工具推薦
MySQL常用維護(hù)管理工具
MySQL數(shù)據(jù)庫(kù)啟動(dòng)失敗1067進(jìn)程意外終止的解決辦法總結(jié)
人氣排行
10款MySQL數(shù)據(jù)庫(kù)客戶端圖形界面管理工具推薦
MySQL數(shù)據(jù)庫(kù)啟動(dòng)失敗1067進(jìn)程意外終止的解決辦法總結(jié)
Mysql 1045錯(cuò)誤解決辦法
MySQL服務(wù)器進(jìn)程CPU占用100%解決辦法
MySQL導(dǎo)出導(dǎo)入命令的用例
MySQL連接字符串的實(shí)際操作步驟匯總
MySQL無(wú)法啟動(dòng)、無(wú)法停止各種解決方法總結(jié)
三種常用的MySQL建表語(yǔ)句