站内搜索: 请输入搜索关键词
当前页面: 在线文档首页 > MySQL 5.1参考手册中文版

Chapter聽10.聽Character Set Support - MySQL 5.1参考手册中文版

绗10绔狅細瀛楃闆嗘敮鎸

鏈珷璁ㄨ浠ヤ笅涓婚锛

         浠涔堟槸瀛楃闆嗗拰鏍″瑙勫垯锛

         澶氱骇榛樿绯荤粺

         瀛楃闆嗚娉

         鐩稿叧鍑芥暟鍜岃繍绠

         Unicode鏀寔

         姣忎釜瀛楃闆嗗拰鏍″瑙勫垯鐨勫惈涔

MySQL5.1涓殑瀛楃闆嗘敮鎸佸寘鎷湪MyISAMMEMORYInnoDB瀛樺偍寮曟搸涓

10.1. 甯歌瀛楃闆嗗拰鏍″

瀛楃闆鏄竴濂楃鍙峰拰缂栫爜銆鏍″瑙勫垯鏄湪瀛楃闆嗗唴鐢ㄤ簬姣旇緝瀛楃鐨勪竴濂楄鍒欍傝鎴戜滑浣跨敤涓涓亣鎯冲瓧绗﹂泦鐨勪緥瀛愭潵鍖哄埆娓呮銆

鍋囪鎴戜滑鏈変竴涓瓧姣嶈〃浣跨敤浜嗗洓涓瓧姣嶏細鈥A鈥欍佲B鈥欍佲a鈥欍佲b鈥欍傛垜浠负姣忎釜瀛楁瘝璧嬩簣涓涓暟鍊硷細鈥A=0锛屸B= 1锛屸a= 2锛屸b= 3銆傚瓧姣嶁A鈥欐槸涓涓鍙凤紝鏁板瓧0鏄A鈥欑殑缂栫爜锛岃繖鍥涗釜瀛楁瘝鍜屽畠浠殑缂栫爜缁勫悎鍦ㄤ竴璧锋槸涓涓瀛楃闆

鍋囪鎴戜滑甯屾湜姣旇緝涓や釜瀛楃涓茬殑鍊硷細鈥A鈥欏拰鈥B鈥欍傛瘮杈冪殑鏈绠鍗曠殑鏂规硶鏄煡鎵剧紪鐮侊細鈥A鈥欎负0锛屸B鈥欎负1銆傚洜涓0 灏忎簬1锛屾垜浠彲浠ヨ鈥A鈥欏皬浜庘B鈥欍傛垜浠仛鐨勪粎浠呮槸鍦ㄦ垜浠殑瀛楃闆嗕笂搴旂敤浜嗕竴涓 鏍″瑙勫垯銆傛牎瀵硅鍒欐槸涓濂楄鍒欙紙鍦ㄨ繖绉嶆儏鍐典笅浠呬粎鏄竴濂楄鍒欙級锛氣滃缂栫爜杩涜姣旇緝銆鈥濇垜浠О杩欑鍏ㄩ儴鍙兘鐨勮鍒欎腑鐨勬渶绠鍗曠殑 鏍″瑙勫垯涓轰竴涓binary锛堜簩鍏冿級鏍″瑙勫垯銆

浣嗘槸锛屽鏋滄垜浠笇鏈涘皬鍐欏瓧姣嶅拰澶у啓瀛楁瘝鏄瓑浠风殑锛屽簲璇ユ庢牱锛熼偅涔堬紝鎴戜滑灏嗚嚦灏戞湁涓や釜瑙勫垯锛氾紙1锛夋妸灏忓啓瀛楁瘝鈥a鈥欏拰鈥b鈥欒涓轰笌鈥A鈥欏拰鈥B鈥欑瓑浠凤紱锛2锛夌劧鍚庢瘮杈冪紪鐮併傛垜浠О杩欐槸涓涓ぇ灏忓啓涓嶆晱鎰熺殑 鏍″瑙勫垯銆傛瘮浜屽厓鏍″瑙勫垯澶嶆潅涓浜涖

鍦ㄥ疄闄呯敓娲讳腑锛屽ぇ澶氭暟瀛楃闆嗘湁璁稿瀛楃锛氫笉浠呬粎鏄A鈥欏拰鈥B鈥欙紝鑰屾槸鏁翠釜瀛楁瘝琛紝鏈夋椂鍊欐湁璁稿绉嶅瓧姣嶈〃锛屾垨鑰呬竴涓笢鏂圭殑浣跨敤涓婂崈涓瓧绗︾殑涔﹀啓绯荤粺锛岃繕鏈夎澶氱壒娈婄鍙峰拰鏍囩偣绗﹀彿銆傚苟涓斿湪瀹為檯鐢熸椿涓紝澶у鏁 鏍″瑙勫垯鏈夎澶氫釜瑙勫垯锛氫笉浠呬粎鏄ぇ灏忓啓涓嶆晱鎰燂紝杩樺寘鎷噸闊崇涓嶆晱鎰燂紙鈥閲嶉煶绗鈥 鏄檮灞炰簬涓涓瓧姣嶇殑绗﹀彿锛岃薄寰疯鐨勨鈥欑鍙凤級鍜屽瀛楄妭鏄犲皠锛堜緥濡傦紝浣滀负瑙勫垯鈥=OE鈥欏氨鏄袱涓痉璇 鏍″瑙勫垯鐨勪竴绉嶏級銆

MySQL5.1鑳藉鍋氳繖浜涗簨鎯咃細

         浣跨敤澶氱瀛楃闆嗘潵瀛樺偍瀛楃涓

         浣跨敤澶氱鏍″瑙勫垯鏉ユ瘮杈冨瓧绗︿覆

         鍦ㄥ悓涓鍙版湇鍔″櫒銆佸悓涓涓暟鎹簱鎴栫敋鑷冲湪鍚屼竴涓〃涓娇鐢ㄤ笉鍚屽瓧绗﹂泦鎴栨牎瀵硅鍒欐潵娣峰悎瀛楃涓

         鍏佽瀹氫箟浠讳綍绾у埆鐨勫瓧绗﹂泦鍜屾牎瀵硅鍒

鍦ㄨ繖浜涙柟闈紝MySQL5.1涓嶄粎姣MySQL4.1浠ュ墠鐨勭増鏈伒娲诲緱澶氾紝鑰屼笖姣斿叾瀹冨ぇ澶氭暟鏁版嵁搴撶鐞嗙郴缁熻秴鍓嶈澶氥備絾鏄紝涓轰簡鏈夋晥鍦颁娇鐢ㄨ繖浜涘姛鑳斤紝浣犻渶瑕佷簡瑙e摢浜涘瓧绗﹂泦鍜 鏍″瑙勫垯鏄彲鐢ㄧ殑锛屾庢牱鏀瑰彉榛樿鍊硷紝浠ュ強瀹冧滑鎬庢牱褰卞搷瀛楃鎿嶄綔绗﹀拰瀛楃涓插嚱鏁扮殑琛屼负銆

10.2. MySQL涓殑瀛楃闆嗗拰鏍″

MySQL鏈嶅姟鍣ㄨ兘澶熸敮鎸佸绉嶅瓧绗﹂泦銆傚彲浠ヤ娇鐢SHOW CHARACTER SET璇彞鍒楀嚭鍙敤鐨勫瓧绗﹂泦锛

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 |
...

锛堝畬鏁村垪琛ㄥ弬瑙10.10鑺傦紝鈥淢ySQL鏀寔鐨勫瓧绗﹂泦鍜屾牎瀵光銆傦級

浠讳綍涓涓粰瀹氱殑瀛楃闆嗚嚦灏戞湁涓涓牎瀵硅鍒欍傚畠鍙兘鏈夊嚑涓牎瀵硅鍒欍

瑕佹兂鍒楀嚭涓涓瓧绗﹂泦鐨勬牎瀵硅鍒欙紝浣跨敤SHOW COLLATION璇彞銆備緥濡傦紝瑕佹兂鏌ョ湅latin1锛堚瑗挎ISO-8859-1锛夊瓧绗﹂泦鐨 鏍″瑙勫垯锛屼娇鐢ㄤ笅闈㈢殑璇彞鏌ユ壘閭d簺鍚嶅瓧浠latin1寮澶寸殑 鏍″瑙勫垯锛

mysql> SHOW COLLATION LIKE 'latin1%';
+---------------------+---------+----+---------+----------+---------+
| Collation           | Charset | Id | Default | Compiled | Sortlen |
+---------------------+---------+----+---------+----------+---------+
| latin1_german1_ci   | latin1  |  5 |         |          |       0 |
| latin1_swedish_ci   | latin1  |  8 | Yes     | Yes      |       1 |
| latin1_danish_ci    | latin1  | 15 |         |          |       0 |
| latin1_german2_ci   | latin1  | 31 |         | Yes      |       2 |
| latin1_bin          | latin1  | 47 |         | Yes      |       1 |
| latin1_general_ci   | latin1  | 48 |         |          |       0 |
| latin1_general_cs   | latin1  | 49 |         |          |       0 |
| latin1_spanish_ci   | latin1  | 94 |         |          |       0 |
+---------------------+---------+----+---------+----------+---------+

latin1鏍″瑙勫垯鏈変笅闈㈢殑鍚箟锛

鏍″瑙勫垯

鍚箟

latin1_german1_ci

寰峰浗DIN-1

latin1_swedish_ci

鐟炲吀/鑺叞

latin1_danish_ci

涓归害/鎸▉

latin1_german2_ci

寰峰浗 DIN-2

latin1_bin

绗﹀悎latin1缂栫爜鐨勪簩杩涘埗

latin1_general_ci

澶氱璇█(瑗挎)

latin1_general_cs

澶氱璇█(瑗挎ISO),澶у皬鍐欐晱鎰

latin1_spanish_ci

鐜颁唬瑗跨彮鐗

鏍″瑙勫垯涓鑸湁杩欎簺鐗瑰緛锛

         涓や釜涓嶅悓鐨勫瓧绗﹂泦涓嶈兘鏈夌浉鍚岀殑鏍″瑙勫垯銆

         姣忎釜瀛楃闆嗘湁涓涓榛樿鏍″瑙勫垯銆備緥濡傦紝latin1榛樿鏍″瑙勫垯鏄latin1_swedish_ci

         瀛樺湪鏍″瑙勫垯鍛藉悕绾﹀畾锛氬畠浠互鍏剁浉鍏崇殑瀛楃闆嗗悕寮濮嬶紝閫氬父鍖呮嫭涓涓瑷鍚嶏紝骞朵笖浠_ci锛堝ぇ灏忓啓涓嶆晱鎰燂級銆_cs锛堝ぇ灏忓啓鏁忔劅锛夋垨_bin锛堜簩鍏冿級缁撴潫銆

10.3. 纭畾榛樿瀛楃闆嗗拰鏍″

瀛楃闆嗗拰鏍″瑙勫垯鏈4涓骇鍒殑榛樿璁剧疆锛氭湇鍔″櫒绾с佹暟鎹簱绾с佽〃绾у拰杩炴帴绾с備互涓嬫弿杩板彲鑳芥樉寰楀鏉傦紝浣嗘槸鍦ㄥ疄闄呭簲鐢ㄤ腑鍙互鍙戠幇浣跨敤澶氱绾у埆浼氫娇缁撴灉鑷劧鑰屾槑鏄俱

10.3.1. 鏈嶅姟鍣ㄥ瓧绗﹂泦鍜屾牎瀵

MySQL鏈嶅姟鍣ㄦ湁涓涓湇鍔″櫒瀛楃闆嗗拰涓涓湇鍔″櫒鏍″瑙勫垯锛屽畠浠潎涓嶈兘璁剧疆涓虹┖銆

MySQL鎸夌収濡備笅鏂规硶纭畾鏈嶅姟鍣ㄥ瓧绗﹂泦鍜屾湇鍔″櫒鏍″瑙勫垯锛

         褰撴湇鍔″櫒鍚姩鏃舵牴鎹湁鏁堢殑閫夐」璁剧疆

         鏍规嵁杩愯鏃剁殑璁惧畾鍊

鍦ㄦ湇鍔″櫒绾у埆锛岀‘瀹氭柟娉曞緢绠鍗曘傚綋鍚姩mysqld鏃讹紝鏍规嵁浣跨敤鐨勫垵濮嬮夐」璁剧疆鏉ョ‘瀹氭湇鍔″櫒瀛楃闆嗗拰 鏍″瑙勫垯銆傚彲浠ヤ娇鐢--default-character-set璁剧疆瀛楃闆嗭紝骞朵笖鍙互鍦ㄥ瓧绗﹂泦鍚庨潰涓 鏍″瑙勫垯娣诲姞--default-collation銆傚鏋滄病鏈夋寚瀹氫竴涓瓧绗﹂泦锛岄偅灏变笌--default-character-set=latin1鐩稿悓銆濡傛灉浣犱粎鎸囧畾浜嗕竴涓瓧绗﹂泦锛堜緥濡傦紝latin1锛夛紝浣嗘槸娌℃湁鎸囧畾涓涓 鏍″瑙勫垯锛岄偅灏变笌--default-charset=latin1 --default-collation=latin1_swedish_ci鐩稿悓鍥犱负latin1_swedish_cilatin1榛樿鏍″瑙勫垯銆傚洜姝わ紝浠ヤ笅涓変釜鍛戒护鏈夌浉鍚岀殑鏁堟灉锛

shell> mysqld

shell> mysqld --default-character-set=latin1

shell> mysqld --default-character-set=latin1 \

           --default-collation=latin1_swedish_ci

鏇存敼璁惧畾鍊肩殑涓涓柟娉曟槸閫氳繃閲嶆柊缂栬瘧銆傚鏋滃笇鏈涘湪浠庢簮绋嬪簭鏋勫缓鏃舵洿鏀归粯璁ゆ湇鍔″櫒瀛楃闆嗗拰鏍″瑙勫垯锛屼娇鐢細--with-charset--with-collation浣滀负configure鐨勫弬閲忋備緥濡傦細

shell> ./configure --with-charset=latin1

鎴栬咃細

shell> ./configure --with-charset=latin1 \

           --with-collation=latin1_german1_ci

mysqldconfigure閮介獙璇佸瓧绗﹂泦/鏍″瑙勫垯缁勫悎鏄惁鏈夋晥銆傚鏋滄棤鏁堬紝姣忎釜绋嬪簭閮芥樉绀轰竴涓敊璇俊鎭紝鐒跺悗缁堟銆

褰撳墠鐨勬湇鍔″櫒瀛楃闆嗗拰鏍″瑙勫垯鍙互鐢ㄤ綔character_set_servercollation_server绯荤粺鍙橀噺鐨勫笺傚湪杩愯鏃惰兘澶熸敼鍙樿繖浜涘彉閲忕殑鍊笺

10.3.2. 鏁版嵁搴撳瓧绗﹂泦鍜屾牎瀵

姣忎竴涓暟鎹簱鏈変竴涓暟鎹簱瀛楃闆嗗拰涓涓暟鎹簱鏍″瑙勫垯锛屽畠涓嶈兘澶熶负绌恒CREATE DATABASEALTER DATABASE璇彞鏈変竴涓彲閫夌殑瀛愬彞鏉ユ寚瀹氭暟鎹簱瀛楃闆嗗拰鏍″瑙勫垯锛
CREATE DATABASE db_name
    [[DEFAULT] CHARACTER SET charset_name]
    [[DEFAULT] COLLATE collation_name]
 
ALTER DATABASE db_name
    [[DEFAULT] CHARACTER SET charset_name]
    [[DEFAULT] COLLATE collation_name]

渚嬪锛

CREATE DATABASE db_name
    DEFAULT CHARACTER SET latin1 COLLATE latin1_swedish_ci;

MySQL杩欐牱閫夋嫨鏁版嵁搴撳瓧绗﹂泦鍜屾暟鎹簱鏍″瑙勫垯锛

         濡傛灉鎸囧畾浜CHARACTER SET XCOLLATE Y锛岄偅涔堥噰鐢ㄥ瓧绗﹂泦X鍜屾牎瀵硅鍒Y

         濡傛灉鎸囧畾浜CHARACTER SET X鑰屾病鏈夋寚瀹COLLATE Y锛岄偅涔堥噰鐢CHARACTER SET XCHARACTER SET X鐨勯粯璁ゆ牎瀵硅鍒欍

         鍚﹀垯锛岄噰鐢ㄦ湇鍔″櫒瀛楃闆嗗拰鏈嶅姟鍣ㄦ牎瀵硅鍒欍

MySQLCREATE DATABASE ... DEFAULT CHARACTER SET ...璇硶涓庢爣鍑SQLCREATE SCHEMA ... CHARACTER SET ...璇硶绫讳技銆傚洜姝わ紝鍙互鍦ㄥ悓涓涓MySQL鏈嶅姟鍣ㄤ笂鍒涘缓浣跨敤涓嶅悓瀛楃闆嗗拰 鏍″瑙勫垯鐨勬暟鎹簱銆

濡傛灉鍦CREATE TABLE璇彞涓病鏈夋寚瀹氳〃瀛楃闆嗗拰鏍″瑙勫垯锛屽垯浣跨敤鏁版嵁搴撳瓧绗﹂泦鍜屾牎瀵硅鍒欎綔涓洪粯璁ゅ笺傚畠浠病鏈夊叾瀹冪洰鐨勩

榛樿鏁版嵁搴撶殑瀛楃闆嗗拰鏍″瑙勫垯鍙互鐢ㄤ綔character_set_databasecollation_database绯荤粺鍙橀噺銆傛棤璁轰綍鏃堕粯璁ゆ暟鎹簱鏇存敼浜嗭紝鏈嶅姟鍣ㄩ兘璁剧疆杩欎袱涓彉閲忕殑鍊笺傚鏋滄病鏈 榛樿鏁版嵁搴擄紝杩欎袱涓彉閲忎笌鐩稿簲鐨勬湇鍔″櫒绾у埆鐨勫彉閲忥紙character_set_servercollation_server锛夊叿鏈夌浉鍚岀殑鍊笺

10.3.3. 琛ㄥ瓧绗﹂泦鍜屾牎瀵

姣忎竴涓〃鏈変竴涓〃瀛楃闆嗗拰涓涓牎瀵硅鍒欙紝瀹冧笉鑳戒负绌恒備负鎸囧畾琛ㄥ瓧绗﹂泦鍜屾牎瀵硅鍒欙紝CREATE TABLE ALTER TABLE璇彞鏈変竴涓彲閫夌殑瀛愬彞锛
CREATE TABLE tbl_name (column_list)
    [DEFAULT CHARACTER SET charset_name [COLLATE collation_name]]
 
ALTER TABLE tbl_name
    [DEFAULT CHARACTER SET charset_name] [COLLATE collation_name]

渚嬪锛

CREATE TABLE t1 ( ... )

DEFAULT CHARACTER SET latin1 COLLATE latin1_danish_ci;

MySQL鎸夌収涓嬮潰鐨勬柟寮忛夋嫨琛ㄥ瓧绗﹂泦鍜 鏍″瑙勫垯锛

         濡傛灉鎸囧畾浜CHARACTER SET XCOLLATE Y锛岄偅涔堥噰鐢CHARACTER SET XCOLLATE Y

         濡傛灉鎸囧畾浜CHARACTER SET X鑰屾病鏈夋寚瀹COLLATE Y锛岄偅涔堥噰鐢CHARACTER SET XCHARACTER SET X鐨勯粯璁ゆ牎瀵硅鍒欍

         鍚﹀垯锛岄噰鐢ㄦ湇鍔″櫒瀛楃闆嗗拰鏈嶅姟鍣ㄦ牎瀵硅鍒欍

濡傛灉鍦ㄥ垪瀹氫箟涓病鏈夋寚瀹氬垪瀛楃闆嗗拰鏍″瑙勫垯锛屽垯榛樿浣跨敤琛ㄥ瓧绗﹂泦鍜屾牎瀵硅鍒欍傝〃瀛楃闆嗗拰鏍″瑙勫垯鏄MySQL鐨勬墿灞;鍦ㄦ爣鍑SQL涓病鏈夈

10.3.4. 鍒楀瓧绗﹂泦鍜屾牎瀵

姣忎竴涓瀛楃鈥濆垪锛堝嵆锛CHARVARCHARTEXT绫诲瀷鐨勫垪锛夋湁涓涓垪瀛楃闆嗗拰涓涓垪 鏍″瑙勫垯锛屽畠涓嶈兘涓虹┖銆傚垪瀹氫箟璇硶鏈変竴涓彲閫夊瓙鍙ユ潵鎸囧畾鍒楀瓧绗﹂泦鍜屾牎瀵硅鍒欙細
col_name {CHAR | VARCHAR | TEXT} (col_length)
    [CHARACTER SET charset_name [COLLATE collation_name]]

渚嬪锛

CREATE TABLE Table1

(

    column1 VARCHAR(5) CHARACTER SET latin1 COLLATE latin1_german1_ci

);

MySQL鎸夌収涓嬮潰鐨勬柟寮忛夋嫨鍒楀瓧绗﹂泦鍜屾牎瀵硅鍒欙細

         濡傛灉鎸囧畾浜CHARACTER SET XCOLLATE Y锛岄偅涔堥噰鐢CHARACTER SET XCOLLATE Y

         濡傛灉鎸囧畾浜CHARACTER SET X鑰屾病鏈夋寚瀹COLLATE Y锛岄偅涔堥噰鐢CHARACTER SET XCHARACTER SET X鐨勯粯璁ゆ牎瀵硅鍒欍

         鍚﹀垯锛岄噰鐢ㄨ〃瀛楃闆嗗拰鏈嶅姟鍣ㄦ牎瀵硅鍒欍

CHARACTER SETCOLLATE瀛愬彞鏄爣鍑嗙殑SQL

10.3.5. 瀛楃闆嗗拰鏍″鍒嗛厤绀轰緥

浠ヤ笅渚嬪瓙鏄剧ず浜MySQL鎬庢牱纭畾榛樿瀛楃闆嗗拰鏍″瑙勫垯銆

绀轰緥1锛氳〃鍜屽垪瀹氫箟

CREATE TABLE t1
(
    c1 CHAR(10) CHARACTER SET latin1 COLLATE latin1_german1_ci
) DEFAULT CHARACTER SET latin2 COLLATE latin2_bin;

鍦ㄨ繖閲屾垜浠湁涓涓垪浣跨敤latin1瀛楃闆嗗拰latin1_german1_ci鏍″瑙勫垯銆傛槸鏄惧紡鐨勫畾涔夛紝鍥犳绠鍗曟槑浜嗐傞渶瑕佹敞鎰忕殑鏄紝鍦ㄤ竴涓latin2琛ㄤ腑瀛樺偍涓涓latin1鍒椾笉浼氬瓨鍦ㄩ棶棰樸

绀轰緥2锛氳〃鍜屽垪瀹氫箟

CREATE TABLE t1
(
    c1 CHAR(10) CHARACTER SET latin1
) DEFAULT CHARACTER SET latin1 COLLATE latin1_danish_ci;

杩欐鎴戜滑鏈変竴涓垪浣跨敤latin1瀛楃闆嗗拰涓涓粯璁ゆ牎瀵硅鍒欍傚敖绠″畠鏄惧緱鑷劧锛岄粯璁ゆ牎瀵硅鍒欏嵈涓嶆槸琛ㄧ骇銆傜浉鍙嶏紝鍥犱负latin1鐨勯粯璁ゆ牎瀵硅鍒欐绘槸latin1_swedish_ci锛屽垪c1鏈変竴涓牎瀵硅鍒latin1_swedish_ci锛堣屼笉鏄latin1_danish_ci锛夈

绀轰緥3锛氳〃鍜屽垪瀹氫箟

CREATE TABLE t1
(
    c1 CHAR(10)
) DEFAULT CHARACTER SET latin1 COLLATE latin1_danish_ci;

鎴戜滑鏈変竴涓垪浣跨敤涓涓粯璁ゅ瓧绗﹂泦鍜屼竴涓粯璁ゆ牎瀵硅鍒欍傚湪杩欑鎯呭喌涓嬶紝MySQL鏌ユ壘琛ㄧ骇鍒潵纭畾鍒楀瓧绗﹂泦鍜 鏍″瑙勫垯銆傚洜姝わ紝鍒c1鐨勫瓧绗﹂泦鏄latin1锛屽畠鐨 鏍″瑙勫垯鏄latin1_danish_ci

绀轰緥4锛氭暟鎹簱銆佽〃鍜屽垪瀹氫箟

CREATE DATABASE d1
    DEFAULT CHARACTER SET latin2 COLLATE latin2_czech_ci;
USE d1;
CREATE TABLE t1
(
    c1 CHAR(10)
);

鎴戜滑鍒涘缓浜嗕竴涓病鏈夋寚瀹氬瓧绗﹂泦鍜屾牎瀵硅鍒欑殑鍒椼傛垜浠篃娌℃湁鎸囧畾琛ㄧ骇瀛楃闆嗗拰鏍″瑙勫垯銆傚湪杩欑鎯呭喌涓嬶紝MySQL鏌ユ壘鏁版嵁搴撶骇鐨勭浉鍏宠缃傦紙鏁版嵁搴撶殑璁剧疆鍙樹负琛ㄧ殑璁剧疆锛屽叾鍚庡彉涓哄垪鐨勮缃傦級鍥犳锛屽垪c1鐨勫瓧绗﹂泦涓烘槸latin2瀹冪殑 鏍″瑙勫垯鏄latin2_czech_ci

10.3.6. 杩炴帴瀛楃闆嗗拰鏍″

涓浜涘瓧绗﹂泦鍜屾牎瀵硅鍒欑郴缁熷彉閲忎笌瀹㈡埛绔拰鏈嶅姟鍣ㄧ殑浜や簰鏈夊叧銆傚湪鍓嶉潰鐨勭珷鑺備腑宸茬粡鎻愬埌杩囬儴鍒嗗唴瀹癸細

         鏈嶅姟鍣ㄥ瓧绗﹂泦鍜屾牎瀵硅鍒欏彲浠ョ敤浣character_set_servercollation_server鍙橀噺鐨勫笺

         榛樿鏁版嵁搴撶殑瀛楃闆嗗拰鏍″瑙勫垯鍙互鐢ㄤ綔character_set_databasecollation_database鍙橀噺鐨勫笺

鍦ㄥ鎴风鍜屾湇鍔″櫒鐨勮繛鎺ュ鐞嗕腑涔熸秹鍙婁簡瀛楃闆嗗拰鏍″瑙勫垯鍙橀噺銆傛瘡涓涓鎴风鏈変竴涓繛鎺ョ浉鍏崇殑瀛楃闆嗗拰鏍″瑙勫垯鍙橀噺銆

鑰冭檻浠涔堟槸涓涓杩炴帴鈥濓細瀹冩槸杩炴帴鏈嶅姟鍣ㄦ椂鎵浣滅殑浜嬫儏銆傚鎴风鍙戦SQL璇彞锛屼緥濡傛煡璇紝閫氳繃杩炴帴鍙戦佸埌鏈嶅姟鍣ㄣ傛湇鍔″櫒閫氳繃杩炴帴鍙戦佸搷搴旂粰瀹㈡埛绔紝渚嬪缁撴灉闆嗐傚浜庡鎴风杩炴帴锛岃繖鏍蜂細瀵艰嚧涓浜涘叧浜庤繛鎺ョ殑瀛楃闆嗗拰 鏍″瑙勫垯鐨勯棶棰橈紝杩欎簺闂鍧囪兘澶熼氳繃绯荤粺鍙橀噺鏉ヨВ鍐筹細

         褰撴煡璇㈢寮瀹㈡埛绔悗锛屽湪鏌ヨ涓娇鐢ㄥ摢绉嶅瓧绗﹂泦锛

鏈嶅姟鍣ㄤ娇鐢character_set_client鍙橀噺浣滀负瀹㈡埛绔彂閫佺殑鏌ヨ涓娇鐢ㄧ殑瀛楃闆嗐

         鏈嶅姟鍣ㄦ帴鏀跺埌鏌ヨ鍚庡簲璇ヨ浆鎹负鍝瀛楃闆嗭紵

杞崲鏃讹紝鏈嶅姟鍣ㄤ娇鐢character_set_connectioncollation_connection绯荤粺鍙橀噺銆傚畠灏嗗鎴风鍙戦佺殑鏌ヨ浠character_set_client绯荤粺鍙橀噺杞崲鍒character_set_connection锛堥櫎闈炲瓧绗︿覆鏂囧瓧鍏锋湁璞_latin1_utf8鐨勫紩浠嬭瘝锛夈collation_connection瀵规瘮杈冩枃瀛楀瓧绗︿覆鏄噸瑕佺殑銆傚浜庡垪鍊肩殑瀛楃涓叉瘮杈冿紝瀹冧笉閲嶈锛屽洜涓哄垪鍏锋湁鏇撮珮鐨 鏍″瑙勫垯浼樺厛绾с

         鏈嶅姟鍣ㄥ彂閫佺粨鏋滈泦鎴栬繑鍥為敊璇俊鎭埌瀹㈡埛绔箣鍓嶅簲璇ヨ浆鎹负鍝瀛楃闆嗭紵

character_set_results鍙橀噺鎸囩ず鏈嶅姟鍣ㄨ繑鍥炴煡璇㈢粨鏋滃埌瀹㈡埛绔娇鐢ㄧ殑瀛楃闆嗐傚寘鎷粨鏋滄暟鎹紝渚嬪鍒楀煎拰缁撴灉鍏冩暟鎹紙濡傚垪鍚嶏級銆

浣犺兘澶熻皟鏁磋繖浜涘彉閲忕殑璁剧疆锛屾垨鍙互渚濊禆榛樿鍊硷紙杩欐牱锛屼綘鍙互璺宠繃鏈珷锛夈

鏈変袱涓鍙ュ奖鍝嶈繛鎺ュ瓧绗﹂泦锛

SET NAMES 'charset_name'
SET CHARACTER SET charset_name

SET NAMES鏄剧ず瀹㈡埛绔彂閫佺殑SQL璇彞涓娇鐢ㄤ粈涔堝瓧绗﹂泦銆傚洜姝わ紝SET NAMES 'cp1251'璇彞鍛婅瘔鏈嶅姟鍣ㄢ灏嗘潵浠庤繖涓鎴风浼犳潵鐨勪俊鎭噰鐢ㄥ瓧绗﹂泦cp1251銆傚畠杩樹负鏈嶅姟鍣ㄥ彂閫佸洖瀹㈡埛绔殑缁撴灉鎸囧畾浜嗗瓧绗﹂泦銆傦紙渚嬪锛屽鏋滀綘浣跨敤涓涓SELECT璇彞瀹冭〃绀哄垪鍊间娇鐢ㄤ簡浠涔堝瓧绗﹂泦銆傦級

SET NAMES 'x'璇彞涓庤繖涓変釜璇彞绛変环锛

mysql> SET character_set_client = x;
mysql> SET character_set_results = x;
mysql> SET character_set_connection = x;

x璁剧疆涓character_set_connection涔熷氨璁剧疆浜collation_connectionx鐨勯粯璁ゆ牎瀵硅鍒欍

SET CHARACTER SET璇彞鏄被浼肩殑锛屼絾鏄负 榛樿鏁版嵁搴撹缃繛鎺ュ瓧绗﹂泦鍜屾牎瀵硅鍒欍SET CHARACTER SET x璇彞涓庤繖涓変釜璇彞绛変环锛

mysql> SET character_set_client = x;
mysql> SET character_set_results = x;
mysql> SET collation_connection = @@collation_database;

褰撲竴涓鎴风杩炴帴鏃讹紝瀹冨悜鏈嶅姟鍣ㄥ彂閫佸笇鏈涗娇鐢ㄧ殑瀛楃闆嗗悕绉般傛湇鍔″櫒涓洪偅涓瓧绗﹂泦璁剧疆character_set_clientcharacter_set_resultscharacter_set_connection鍙橀噺銆傦紙瀹為檯涓婏紝鏈嶅姟鍣ㄤ负浣跨敤璇ュ瓧绗﹂泦鎵ц涓涓SET NAMES鎿嶄綔銆傦級

瀵逛簬mysql瀹㈡埛绔紝濡傛灉浣犲笇鏈涗娇鐢ㄤ笌榛樿瀛楃闆嗕笉鍚岀殑瀛楃闆嗭紝涓嶉渶瑕佹瘡娆″惎鍔ㄦ椂鎵цSET NAMES璇彞銆傚彲浠ュ湪mysql璇彞琛屼腑鎴栬呴夐」鏂囦欢涓坊鍔犱竴涓--default-character-set閫夐」璁剧疆銆備緥濡傦紝浣犳瘡娆¤繍琛mysql鏃讹紝浠ヤ笅鐨勯夐」鏂囦欢璁剧疆鎶婁笁涓瓧绗﹂泦鍙橀噺淇敼涓koi8r

[mysql]

default-character-set=koi8r

渚嬪锛氬亣璁column1瀹氫箟涓CHAR(5) CHARACTER SET latin2銆傚鏋滄病鏈夎瀹SET NAMESSET CHARACTER SET锛岄偅涔堝浜SELECT column1 FROM t锛屽綋杩炴帴鍚庯紝鏈嶅姟鍣ㄤ娇鐢ㄥ鎴风鎸囧畾鐨勫瓧绗﹂泦杩斿洖鍒column1鐨勬墍鏈夊笺傚彟涓鏂归潰锛屽鏋滀綘璁惧畾SET NAMES 'latin1'SET CHARACTER SET latin1锛岄偅涔堝彂閫佺粨鏋滀箣鍓嶏紝鏈嶅姟鍣ㄨ浆鎹latin2鍊煎埌latin1銆傝浆鎹㈠彲鑳戒細涓㈠け閭d簺涓嶅睘浜庝袱绉嶅瓧绗﹂泦鐨勫瓧绗︺

濡傛灉涓嶅笇鏈涙湇鍔″櫒鎵ц浠讳綍杞崲锛岃缃character_set_resultsNULL

mysql> SET character_set_results = NULL;

10.3.7. 瀛楃涓叉枃瀛楀瓧绗﹂泦鍜屾牎瀵

姣忎竴瀛楃涓插瓧绗︽枃瀛楁湁涓涓瓧绗﹂泦鍜屼竴涓牎瀵硅鍒欙紝瀹冧笉鑳戒负绌恒

涓涓瓧绗︿覆鏂囧瓧鍙兘鏈変竴涓彲閫夌殑瀛楃闆嗗紩浠嬭瘝鍜COLLATE瀛愬彞锛

[_charset_name]'string' [COLLATE collation_name]

渚嬪锛

SELECT 'string';
SELECT _latin1'string';
SELECT _latin1'string' COLLATE latin1_danish_ci;

瀵逛簬绠鍗曠殑璇彞SELECT 'string'锛屽瓧绗︿覆浣跨敤鐢character_set_connectioncollation_connection绯荤粺鍙橀噺瀹氫箟鐨勫瓧绗﹂泦鍜 鏍″瑙勫垯銆

_charset_name琛ㄨ揪寮忔寮忕О鍋氫竴涓寮曚粙璇銆傚畠鍛婅瘔瑙f瀽绋嬪簭锛屸滃悗闈㈠皢瑕佸嚭鐜扮殑瀛楃涓蹭娇鐢ㄥ瓧绗﹂泦X鈥濆洜涓轰互鍓嶄汉浠姝ゆ劅鍒板洶鎯戯紝鎴戜滑寮鸿皟寮曚粙璇嶄笉瀵艰嚧浠讳綍杞崲; 瀹冧粎鏄竴涓鍙凤紝涓嶆敼鍙樺瓧绗︿覆鐨勫笺傚紩浠嬭瘝鍦ㄦ爣鍑嗗崄鍏繘鍒跺瓧姣嶅拰鏁板瓧鍗佸叚杩涘埗绗﹀彿锛x'literal'0xnnnn锛変腑鏄悎娉曠殑锛屼互鍙锛堝綋鍦ㄤ竴涓紪绋嬭瑷鎺ュ彛涓娇鐢ㄩ澶勭悊鐨勮鍙ユ椂杩涜鍙傛暟鏇挎崲锛夈

渚嬪锛

SELECT _latin1 x'AABBCC';
SELECT _latin1 0xAABBCC;
SELECT _latin1 ?;

MySQL杩欐牱纭畾涓涓枃瀛楀瓧绗﹂泦鍜屾牎瀵硅鍒欙細

         濡傛灉鎸囧畾浜CHARACTER SET XCOLLATE Y锛岄偅涔堜娇鐢CHARACTER SET XCOLLATE Y

         濡傛灉鎸囧畾浜CHARACTER SET X鑰屾病鏈夋寚瀹COLLATE Y锛岄偅涔堜娇鐢CHARACTER SET XCHARACTER SET X鐨勯粯璁ゆ牎瀵硅鍒欍

         鍚﹀垯锛屼娇鐢ㄩ氳繃character_set_connection collation_connection绯荤粺鍙橀噺缁欏嚭鐨勫瓧绗﹂泦鍜 鏍″瑙勫垯銆

渚嬪锛

         浣跨敤latin1瀛楃闆嗗拰latin1_german1_ci鏍″瑙勫垯鐨勫瓧绗︿覆锛

                SELECT _latin1'Mller' COLLATE latin1_german1_ci;

         浣跨敤latin1瀛楃闆嗗拰鍏堕粯璁ゆ牎瀵硅鍒欑殑瀛楃涓诧紙鍗筹紝latin1_swedish_ci锛夛細

                SELECT _latin1'Mller';

         浣跨敤杩炴帴榛樿瀛楃闆嗗拰鏍″瑙勫垯鐨勫瓧绗︿覆锛

                SELECT 'Mller';

瀛楃闆嗗紩浠嬭瘝鍜COLLATE瀛愬彞鏄牴鎹爣鍑SQL瑙勮寖瀹炵幇鐨勩

10.3.8. 鍦⊿QL璇彞涓娇鐢–OLLATE

  • 浣跨敤COLLATE瀛愬彞锛岃兘澶熶负涓涓瘮杈冭鐩栦换浣曢粯璁ゆ牎瀵硅鍒欍COLLATE鍙互鐢ㄤ簬澶氱SQL璇彞涓備笅闈㈡槸涓浜涗緥瀛愶細

             浣跨敤ORDER BY

                    SELECT k
                    FROM t1
                    ORDER BY k COLLATE latin1_german2_ci;

             浣跨敤AS

                    SELECT k COLLATE latin1_german2_ci AS k1
                    FROM t1
                    ORDER BY k1;

             浣跨敤GROUP BY

                    SELECT k
                    FROM t1
                    GROUP BY k COLLATE latin1_german2_ci;

             浣跨敤鑱氬悎鍑芥暟锛

                    SELECT MAX(k COLLATE latin1_german2_ci)
                    FROM t1;

             浣跨敤DISTINCT

                    SELECT DISTINCT k COLLATE latin1_german2_ci
                    FROM t1;

             浣跨敤WHERE

                         SELECT *
                         FROM t1
                         WHERE _latin1 'Mller' COLLATE latin1_german2_ci = k;
                         SELECT *
                         FROM t1
                         WHERE k LIKE _latin1 'Mller' COLLATE latin1_german2_ci;

             浣跨敤HAVING

                    SELECT k
                    FROM t1
                    GROUP BY k
                    HAVING k = _latin1 'Mller' COLLATE latin1_german2_ci;

10.3.9.聽COLLATE瀛愬彞浼樺厛

COLLATE瀛愬彞鏈夎緝楂樼殑浼樺厛绾э紙楂樹簬||锛夛紝鍥犳涓嬮潰涓や釜琛ㄨ揪寮忔槸绛変环鐨勶細

x || y COLLATE z
x || (y COLLATE z)

10.3.10.聽BINARY鎿嶄綔绗

BINARY鎿嶄綔绗︽槸COLLATE瀛愬彞鐨勪竴涓熻绗︺BINARY 'x'绛変环涓'x' COLLATE y锛岃繖閲y鏄瓧绗﹂泦'x'浜屽厓 鏍″瑙勫垯鐨勫悕瀛椼傛瘡涓涓瓧绗﹂泦鏈変竴涓簩鍏冩牎瀵硅鍒欍備緥濡傦紝latin1瀛楃闆嗙殑浜屽厓 鏍″瑙勫垯鏄latin1_bin锛屽洜姝わ紝濡傛灉鍒a鏄瓧绗﹂泦latin1锛屼互涓嬩袱涓鍙ユ湁鐩稿悓鏁堟灉锛
SELECT * FROM t1 ORDER BY BINARY a;
SELECT * FROM t1 ORDER BY a COLLATE latin1_bin;

10.3.11. 鏍″纭畾杈冧负澶嶆潅鐨勪竴浜涚壒娈婃儏鍐

鍦ㄧ粷澶у鏁版煡璇腑锛MySQL浣跨敤鍝鏍″瑙勫垯杩涜姣旇緝鏄緢鏄剧劧鐨勩備緥濡傦紝鍦ㄤ笅鍒楁儏鍐典腑锛屾牎瀵硅鍒欐槑鏄剧殑鏄x鐨勫垪鏍″瑙勫垯鈥濓細

SELECT x FROM T ORDER BY x;
SELECT x FROM T WHERE x = x;
SELECT DISTINCT x FROM T;

浣嗘槸锛屽綋娑夊強澶氫釜鎿嶄綔鏁版椂锛屽彲鑳戒笉鏄庣‘銆備緥濡傦細

SELECT x FROM T WHERE x = 'Y';

杩欎釜鏌ヨ搴旇浣跨敤鍒x鐨 鏍″瑙勫垯锛岃繕鏄瓧绗︿覆鏂囧瓧'Y'鐨 鏍″瑙勫垯锛

鏍囧噯鍖SQL浣跨敤鈥鍙帇缂╂鈥濊鍒欒В鍐宠繖绉嶉棶棰樸傚熀鏈笂锛岃繖涓剰鎬濇槸锛氭棦鐒x'Y'閮芥湁 鏍″瑙勫垯锛屽摢涓牎瀵硅鍒欎紭鍏堬紵杩欏彲鑳芥瘮杈冮毦瑙e喅锛屼絾鏄互涓嬭鍒欓傚悎澶у鏁版儏鍐碉細

         涓涓鍦ㄧ殑COLLATE瀛愬彞鍙帇缂╂ф槸0锛堟牴鏈笉鑳藉帇缂┿傦級

         浣跨敤涓嶅悓鏍″瑙勫垯鐨勪袱涓瓧绗︿覆杩炴帴鐨勫彲鍘嬬缉鎬ф槸1

         鍒楁牎瀵硅鍒欑殑鍙帇缂╂ф槸2

         绯荤粺甯告暟鈥濓紙濡USER()VERSION()鍑芥暟杩斿洖鐨勫瓧绗︿覆锛夊彲鍘嬬缉鎬ф槸3

         鏂囧瓧瑙勫垯鐨勫彲鍘嬬缉鎬ф槸4

         NULL鎴栦粠NULL娲剧敓鐨勮〃杈惧紡鐨勫彲鍘嬬缉鎬ф槸 5

涓婅堪鍙帇缂╂у兼槸MySQL5.1褰撳墠鎵鐢ㄧ殑銆

杩欐牱涓婅堪瑙勫垯鍙互妯$硦瑙e喅锛

         浣跨敤鏈浣庣殑鍙帇缂╂у肩殑鏍″瑙勫垯銆

         濡傛灉涓や晶鏈夌浉鍚岀殑鍙帇缂╂э紝閭d箞濡傛灉鏍″瑙勫垯涓嶅悓鍒欏彂鐢熼敊璇

渚嬪锛

column1 = 'A'

浣跨敤column1鐨勬牎瀵硅鍒

column1 = 'A' COLLATE x

浣跨敤'A'鐨勬牎瀵硅鍒

column1 COLLATE x = 'A' COLLATE y

閿欒

浣跨敤COERCIBILITY锛堬級鍑芥暟纭畾涓涓瓧绗︿覆琛ㄨ揪寮忕殑鍙帇缂╂э細

mysql> SELECT COERCIBILITY('A' COLLATE latin1_swedish_ci);
        -> 0
mysql> SELECT COERCIBILITY(VERSION());
        -> 3
mysql> SELECT COERCIBILITY('A');
        -> 4

12.9.3鑺傦紝鈥滀俊鎭嚱鏁扳

娌℃湁绯荤粺甯告暟鎴栧彲蹇界暐鐨勫帇缂╂с傚嚱鏁板USER()鐨勫彲鍘嬬缉鎬ф槸2鑰屼笉鏄3锛屾枃瀛楃殑鍙帇缂╂ф槸3鑰屼笉鏄4

10.3.12. 鏍″蹇呴』閫傚悎瀛楃闆

璇锋敞鎰忔瘡涓瓧绗﹂泦鏈変竴涓垨澶氫釜鏍″瑙勫垯锛屽苟涓旀瘡涓牎瀵硅鍒欏彧鑳藉睘浜庝竴涓瓧绗﹂泦銆傚洜姝わ紝浠ヤ笅璇彞浼氫骇鐢熶竴涓敊璇俊鎭紝鍥犱负鏍″瑙勫垯latin2_bin瀵逛簬瀛楃闆latin1闈炴硶锛

mysql> SELECT _latin1 'x' COLLATE latin2_bin;

ERROR 1251: COLLATION 'latin2_bin' is not valid

for CHARACTER SET 'latin1'

10.3.13. 鏍″鏁堟灉鐨勭ず渚

鍋囪琛T涓殑鍒X鏈夎繖浜latin1鍒楀硷細

Muffler

Mller

MX Systems

MySQL

鍋囪浣跨敤涓嬮潰鐨勮鍙ヨ幏鍙栧垪鍊硷細

SELECT X FROM T ORDER BY X COLLATE collation_name;

浣跨敤涓嶅悓鏍″瑙勫垯鐨勫垪鍊肩粨鏋滄帓搴忚涓嬭〃锛

latin1_swedish_ci

latin1_german1_ci

latin1_german2_ci

Muffler

Muffler

Mller

MX绯荤粺

Mller

Muffler

Mller

MX绯荤粺

MX绯荤粺

MySQL

MySQL

MySQL

鏈〃鏄剧ず浜嗘垜浠湪ORDER BY瀛楀彞涓娇鐢ㄤ笉鍚屾墍鏍″瑙勫垯鐨勬晥鏋滅殑绀轰緥銆傚湪鏈緥涓鑷翠笉鍚屾帓搴忕殑瀛楃鏄笂闈㈠甫鏈変袱涓渾鐐圭殑U锛夛紝瀹冨湪寰疯涓彂闊充负"U-umlaut"

         绗竴鍒楁樉绀虹殑鏄娇鐢ㄧ憺鍏/鑺叞鏍″瑙勫垯鐨SELECT璇彞鐨勭粨鏋滐紝瀹冭绉颁綔U-umlaut浣跨敤Y鎺掑簭銆

         绗簩鍒楁樉绀虹殑鏄娇鐢ㄥ痉璇DIN-1鏍″瑙勫垯鐨SELECT璇彞鐨勭粨鏋滐紝瀹冭绉颁綔U-umlaut浣跨敤U鎺掑簭銆

         绗笁鍒楁樉绀虹殑鏄娇鐢ㄥ痉璇DIN-2鏍″瑙勫垯鐨SELECT璇彞鐨勭粨鏋滐紝瀹冭绉颁綔U-umlaut浣跨敤UE鎺掑簭銆

10.4. 瀛楃闆嗘敮鎸佸奖鍝嶅埌鐨勬搷浣

鏈妭璁ㄨ鍦MySQL5.1涓冭檻鍒板瓧绗﹂泦淇℃伅鐨勬搷浣溿

10.4.1. 缁撴灉瀛楃涓

MySQL涓湁璁稿鎿嶄綔绗﹀拰鍑芥暟鍙互杩斿洖瀛楃涓层傛湰鑺傚洖绛旇繖涓棶棰橈細杩斿洖鐨勫瓧绗︿覆浣跨敤浠涔堝瓧绗﹂泦鍜 鏍″瑙勫垯锛

瀵逛簬绠鍗曠殑鍑芥暟锛屽嵆鎺ユ敹瀛楃涓茶緭鍏ョ劧鍚庤繑鍥炰竴涓瓧绗︿覆缁撴灉浣滀负杈撳嚭鐨勫嚱鏁帮紝杈撳嚭鐨勫瓧绗﹂泦鍜屾牎瀵硅鍒欎笌鍘熷杈撳叆鐨勭浉鍚屻備緥濡傦紝UPPERX杩斿洖涓涓瓧绗︿覆锛屽叾瀛楃鍜 鏍″瑙勫垯涓X鐩稿悓銆傜被浼肩殑鍑芥暟杩樻湁INSTR()LCASE()LOWER()LTRIM()MID()REPEAT()REPLACE()REVERSE()RIGHT()RPAD()RTRIM()SOUNDEX()SUBSTRING()TRIM()UCASE()UPPER()銆傦紙杩橀渶瑕佹敞鎰忥細REPLACE()鍑芥暟涓嶅悓浜庡叾瀹冨嚱鏁帮紝瀹冩绘槸蹇界暐杈撳叆瀛楃涓茬殑 鏍″瑙勫垯锛屽苟涓旇繘琛屽ぇ灏忓啓涓嶆晱鎰熺殑姣旇緝銆傦級

瀵逛簬鍚堝苟澶氫釜瀛楃涓茶緭鍏ュ苟涓旇繑鍥炲崟涓瓧绗︿覆杈撳嚭鐨勮繍绠楋紝搴旂敤鏍囧噯SQL鈥滆仛鍚瑙勫垯鈥濓細

         濡傛灉瀛樺湪鏄惧紡鐨勬牎瀵硅鍒X锛岄偅涔堜娇鐢X

         濡傛灉瀛樺湪鏄惧紡鐨勬牎瀵硅鍒XY锛岄偅涔堜骇鐢熶竴涓敊璇

         鍚﹀垯锛屽鏋滃叏閮ㄦ牎瀵硅鍒欐槸X锛岄偅涔堜娇鐢X

         鍏跺畠鎯呭喌锛岀粨鏋滄病鏈夋牎瀵硅鍒欍

渚嬪锛屼娇鐢CASE ... WHEN a THEN b WHEN b THEN c COLLATE X END銆傜粨鏋滄牎瀵硅鍒欐槸X銆傚浜CASEUNION||CONCAT()ELT()GREATEST()IF()LEAST()鎯呭喌鐩稿悓銆

瀵逛簬杞崲涓哄瓧绗︽暟鎹殑杩愮畻锛屼粠杩愮畻寰楀埌鐨勭粨鏋滃瓧绗︿覆鐨勫瓧绗﹂泦鍜屾牎瀵硅鍒欑敱character_set_connectioncollation_connection绯荤粺鍙橀噺瀹氫箟銆傝繖閫傜敤浜CAST()CHAR()CONV()FORMAT()HEX()SPACE()鍑芥暟銆

10.4.2.聽CONVERT()

CONVERT锛堬級鎻愪緵涓涓湪涓嶅悓瀛楃闆嗕箣闂磋浆鎹㈡暟鎹殑鏂规硶銆傝娉曟槸锛
CONVERT(expr USING transcoding_name)

MySQL涓紝杞崲浠g爜鍚嶄笌鐩稿簲鐨勫瓧绗﹂泦鍚嶇浉鍚屻

渚嬪瓙锛

SELECT CONVERT(_latin1'Mller' USING utf8);
INSERT INTO utf8table (utf8column)
    SELECT CONVERT(latin1field USING utf8) FROM latin1table;

CONVERT(... USING ...)鏍规嵁鏍囧噯SQL瑙勮寖瀹炴柦銆

鍦ㄤ紶缁SQL妯″紡涓紝濡傛灉浣犺浆鎹竴涓0鈥濇棩鏈熷瓧绗︿覆鍒版棩鏈熺被鍨嬶紝CONVERT锛堬級鍑芥暟杩斿洖NULL銆傚湪MySQL5.1涓繕浜х敓涓鏉¤鍛娿

10.4.3.聽CAST()

浣犱篃鍙互浣跨敤CAST()鍑芥暟灏嗕竴涓瓧绗︿覆杞崲鍒颁竴涓笉鍚岀殑瀛楃闆嗐傝娉曟槸锛

CAST(character_string AS character_data_type CHARACTER SET charset_name)

渚嬪锛

SELECT CAST(_latin1'test' AS CHAR CHARACTER SET utf8);

濡傛灉浣跨敤CAST()鏃舵病鏈夋寚瀹CHARACTER SET锛岀粨鏋滃瓧绗﹂泦鍜屾牎瀵硅鍒欓氳繃character_set_connection collation_connection绯荤粺鍙橀噺瀹氫箟銆傚鏋滅敤CAST()骞跺甫鏈CHARACTER SET X閫夐」锛岄偅涔堢粨鏋滃瓧绗﹂泦鍜屾牎瀵硅鍒欐槸X鍜屽叾 榛樿鐨勬牎瀵硅鍒欍

浣犲彲鑳戒笉鑳藉湪CAST()涓娇鐢COLLATE瀛愬彞锛屼絾鏄綘鍙互鍦ㄥ閮ㄤ娇鐢ㄥ畠銆備篃灏辨槸璇达紝涓嶆槸CAST(... COLLATE ...)锛岃屾槸CAST(...) COLLATE ...

渚嬪锛

SELECT CAST(_latin1'test' AS CHAR CHARACTER SET utf8) COLLATE utf8_bin;

鍦ㄤ紶缁SQL妯″紡涓紝濡傛灉浣犺浆鎹竴涓0鈥濇棩鏈熷瓧绗︿覆鍒版棩鏈熺被鍨嬶紝CAST()鍑芥暟杩斿洖NULL銆傚湪MySQL5.1涓繕浜х敓涓鏉¤鍛娿

10.4.4.聽SHOW璇彞

涓浜SHOW璇彞鎻愪緵棰濆鐨勫瓧绗﹂泦淇℃伅銆傝繖浜涜鍙ュ寘鎷SHOW CHARACTER SETSHOW COLLATIONSHOW CREATE DATABASESHOW CREATE TABLESHOW COLUMNS

SHOW CHARACTER SET鍛戒护鏄剧ず鍏ㄩ儴鍙敤鐨勫瓧绗﹂泦銆傚畠甯︽湁涓涓彲閫夌殑LIKE瀛愬彞鏉ユ寚绀哄尮閰嶅摢浜涘瓧绗﹂泦鍚嶃備緥濡傦細

mysql> SHOW CHARACTER SET LIKE 'latin%';

+---------+-----------------------------+-------------------+--------+

| Charset | Description                 | Default collation | Maxlen |

+---------+-----------------------------+-------------------+--------+

| latin1  | cp1252 West European        | latin1_swedish_ci |      1 |

| latin2  | ISO 8859-2 Central European | latin2_general_ci |      1 |

| latin5  | ISO 8859-9 Turkish          | latin5_turkish_ci |      1 |

| latin7  | ISO 8859-13 Baltic          | latin7_general_ci |      1 |

+---------+-----------------------------+-------------------+--------+

13.5.4.1鑺傦紝鈥淪HOW CHARACTER SET璇硶鈥

SHOW COLLATION璇彞鐨勮緭鍑哄寘鎷叏閮ㄥ彲鐢ㄧ殑瀛楃闆嗐傚畠甯︽湁涓涓彲閫夌殑LIKE瀛愬彞鏉ユ寚绀哄尮閰嶅摢浜 鏍″瑙勫垯鍚嶃備緥濡傦細

mysql> SHOW COLLATION LIKE 'latin1%';
+-------------------+---------+----+---------+----------+---------+
| Collation         | Charset | Id | Default | Compiled | Sortlen |
+-------------------+---------+----+---------+----------+---------+
| latin1_german1_ci | latin1  |  5 |         |          |       0 |
| latin1_swedish_ci | latin1  |  8 | Yes     | Yes      |       0 |
| latin1_danish_ci  | latin1  | 15 |         |          |       0 |
| latin1_german2_ci | latin1  | 31 |         | Yes      |       2 |
| latin1_bin        | latin1  | 47 |         | Yes      |       0 |
| latin1_general_ci | latin1  | 48 |         |          |       0 |
| latin1_general_cs | latin1  | 49 |         |          |       0 |
| latin1_spanish_ci | latin1  | 94 |         |          |       0 |
+-------------------+---------+----+---------+----------+---------+

13.5.4.2鑺傦紝鈥淪HOW COLLATION璇硶鈥

SHOW CREATE DATABASE璇彞鏄剧ず鍒涘缓缁欏畾鏁版嵁搴撶殑CREATE DATABASE璇彞銆傜粨鏋滃寘鎷叏閮ㄦ暟鎹簱閫夐」銆傛敮鎸DEFAULT CHARACTER SETCOLLATE銆傚叏閮ㄦ暟鎹簱閫夐」瀛樺偍鍦ㄥ懡鍚嶄负db.Opt鐨勬枃鏈枃浠朵腑锛岃鏂囦欢鑳藉鍦ㄦ暟鎹簱鐩綍涓壘鍒般

mysql> SHOW CREATE DATABASE test;
+----------+-----------------------------------------------------------------+
| Database | Create Database                                                 |
+----------+-----------------------------------------------------------------+
| test     | CREATE DATABASE `test` /*!40100 DEFAULT CHARACTER SET latin1 */ |
+----------+-----------------------------------------------------------------+

13.5.4.4鑺傦紝鈥淪HOW CREATE DATABASE璇硶鈥

SHOW CREATE TABLESHOW CREATE DATABASE鐩镐技锛屼絾鏄樉绀哄垱寤虹粰瀹氭暟鎹簱鐨CREATE TABLE璇彞銆傚垪瀹氫箟鏄剧ず浠讳綍瀛楃闆嗚鏍硷紝骞朵笖琛ㄩ夐」鍖呮嫭瀛楃闆嗕俊鎭

13.5.4.5鑺傦紝鈥淪HOW CREATE TABLE璇硶鈥

褰撲互SHOW FULL COLUMNS璋冪敤鏃讹紝SHOW COLUMNS璇彞鏄剧ず琛ㄤ腑鍒楃殑鏍″瑙勫垯銆傚叿鏈CHARVARCHARTEXT鏁版嵁绫诲瀷鐨勫垪鏈夐潪NULL鐨 鏍″瑙勫垯銆傛暟鍊煎垪鍜屽叾瀹冮潪瀛楃绫诲瀷鐨勫垪鏈NULL鏍″瑙勫垯銆備緥濡傦細

mysql> SHOW FULL COLUMNS FROM person\G

*************************** 1. row ***************************

     Field: id

      Type: smallint(5) unsigned

 Collation: NULL

      Null: NO

       Key: PRI

   Default: NULL

     Extra: auto_increment

Privileges: select,insert,update,references

   Comment:

*************************** 2. row ***************************

     Field: name

      Type: char(60)

 Collation: latin1_swedish_ci

      Null: NO

       Key:

   Default:

     Extra:

Privileges: select,insert,update,references

   Comment:

瀛楃闆嗕笉鏄樉绀虹殑閮ㄥ垎銆傦紙瀛楃闆嗗悕闅愬惈鍦ㄦ牎瀵硅鍒欏悕涓傦級

13.5.4.3鑺傦紝鈥淪HOW COLUMNS璇硶鈥

10.5. Unicode鏀寔

MySQL 5.1鏀寔涓ょ瀛楃闆嗕互淇濆瓨Unicode鏁版嵁锛

         ucs2UCS-2 Unicode瀛楃闆嗐

         utf8Unicode瀛楃闆嗙殑UTF8缂栫爜銆

UCS-2锛堜簩杩涘埗Unicode琛ㄧず娉曪級涓紝姣忎竴涓瓧绗︾敤涓涓弻瀛楄妭鐨Unicode缂栫爜鏉ヨ〃绀虹殑锛岀涓涓瓧鑺傝〃绀洪噸瑕佺殑鎰忎箟銆備緥濡傦細"LATIN CAPITAL LETTER A"Unicode缂栫爜鏄0x0041锛屽畠鎸夐『搴忓瓨鍌ㄤ负涓や釜瀛楄妭锛0x00 0x41"CYRILLIC SMALL LETTER YERU"Unicode 0x044B锛夐『搴忓瓨鍌ㄤ负涓や釜瀛楄妭锛0x04 0x4B銆傚浜Unicode瀛楃鍜屽畠浠殑缂栫爜锛岃鍙傝Unicode 涓婚〉

褰撳墠锛UCS-2杩樹笉鑳藉鐢ㄤ綔涓哄鎴风瀛楃闆嗭紝杩欐剰鍛崇潃SET NAMES 'ucs2'涓嶈捣浣滅敤銆

UTF8瀛楃闆嗭紙杞崲Unicode琛ㄧず锛夋槸瀛樺偍Unicode鏁版嵁鐨勪竴绉嶅彲閫夋柟娉曘傚畠鏍规嵁 RFC 3629鎵ц銆UTF8瀛楃闆嗙殑鎬濇兂鏄笉鍚Unicode瀛楃閲囩敤鍙橀暱瀛楄妭搴忓垪缂栫爜锛

         鍩烘湰鎷変竵瀛楁瘝銆佹暟瀛楀拰鏍囩偣绗﹀彿浣跨敤涓涓瓧鑺傘

         澶у鏁扮殑娆ф床鍜屼腑涓滄墜鍐欏瓧姣嶉傚悎涓や釜瀛楄妭搴忓垪锛氭墿灞曠殑鎷変竵瀛楁瘝锛堝寘鎷彂闊崇鍙枫侀暱闊崇鍙枫侀噸闊崇鍙枫佷綆闊崇鍙峰拰鍏跺畠闊崇锛夈佽タ閲屽皵瀛楁瘝銆佸笇鑵婅銆佷簹缇庡凹浜氳銆佸笇浼潵璇侀樋鎷変集璇佸彊鍒╀簹璇拰鍏跺畠璇█銆

         闊╄銆佷腑鏂囧拰鏃ユ湰璞″舰鏂囧瓧浣跨敤涓変釜瀛楄妭搴忓垪銆

RFC 3629璇存槑浜嗛噰鐢ㄤ竴鍒板洓涓瓧鑺傜殑缂栫爜搴忓垪銆傚綋鍓嶏紝MySQLUTF8涓嶆敮鎸佸洓涓瓧鑺傘傦紙UTF8缂栫爜鐨勬棫鏍囧噯鏄敱RFC 2279缁欏嚭锛屽畠鎻忚堪浜嗕粠涓鍒板叚涓瓧鑺傜殑UTF8缂栫爜搴忓垪銆RFC 3629琛ュ厖浜嗕綔搴熺殑RFC 2279锛涘洜姝わ紝涓嶅啀浣跨敤5涓瓧鑺傚拰6涓瓧鑺傜殑缂栫爜搴忓垪銆傦級

鎻愮ず锛氫娇鐢UTF8鏃朵负浜嗚妭鐪佺┖闂达紝浣跨敤VARCHAR鑰屼笉瑕佺敤CHAR銆傚惁鍒欙紝MySQL蹇呴』涓轰竴涓CHAR(10) CHARACTER SET utf8鍒楅澶30涓瓧鑺傦紝鍥犱负杩欐槸鍙兘鐨勬渶澶ч暱搴︺

10.6. 鐢ㄤ簬鍏冩暟鎹殑UTF8

鍏冩暟鎹鏄鍏充簬鏁版嵁鐨勬暟鎹鈥濄傛弿杩版暟鎹簱鐨勪换浣曟暟鎹斾綔涓烘暟鎹簱鍐呭鐨勫绔嬮潰鈥旀槸鍏冩暟鎹傚洜姝わ紝鍒楀悕銆佹暟鎹簱鍚嶃佺敤鎴峰悕銆佺増鏈悕浠ュ強浠SHOW璇彞寰楀埌鐨勭粨鏋滀腑鐨勫ぇ閮ㄥ垎瀛楃涓叉槸鍏冩暟鎹傝繕鍖呮嫭INFORMATION_SCHEMA鏁版嵁搴撲腑鐨勮〃涓殑鍐呭锛屽洜涓哄畾涔夌殑閭d簺琛ㄥ瓨鍌ㄥ叧浜庢暟鎹簱瀵硅薄鐨勪俊鎭

鍏冩暟鎹〃杩板繀椤绘弧瓒宠繖浜涢渶姹傦細

         鍏ㄩ儴鍏冩暟鎹繀椤诲湪鍚屼竴瀛楃闆嗗唴銆傚惁鍒欙紝瀵INFORM涓涓TION_SCHEMA鏁版嵁搴撲腑鐨勮〃鎵ц鐨SHOW鍛戒护鍜SELECT鏌ヨ涓嶈兘姝e父宸ヤ綔锛屽洜涓鸿繖浜涜繍绠楃粨鏋滀腑鐨勫悓涓鍒楃殑涓嶅悓琛屽皢浼氫娇鐢ㄤ笉鍚岀殑瀛楃闆嗐

         鍏冩暟鎹繀椤诲寘鎷墍鏈夎瑷鐨勬墍鏈夊瓧绗︺傚惁鍒欙紝鐢ㄦ埛灏嗕笉鑳藉浣跨敤瀹冧滑鑷繁鐨勮瑷鏉ュ懡鍚嶅垪鍜岃〃銆

涓轰簡婊¤冻杩欎袱涓渶姹傦紝MySQL浣跨敤Unicode瀛楃闆嗗瓨鍌ㄥ厓鏁版嵁锛屽嵆UTF8銆傚鏋滀綘浠庝笉浣跨敤閲嶉煶瀛楃锛岃繖涓嶄細瀵艰嚧浠讳綍鐮村潖銆備絾濡傛灉浣犱娇鐢ㄩ噸闊冲瓧绗︼紝搴旇娉ㄦ剰鐨勬槸鍏冩暟鎹槸鐢UTF8瀛樺偍銆

杩欐剰鍛崇潃锛USER()CURRENT_USER()DATABASE()VERSION()鍑芥暟鐨勮繑鍥炲艰 榛樿璁剧疆涓UTF8瀛楃闆嗭紝杩欎笌鍚屼箟鍑芥暟濡SESSION_USER() SYSTEM_USER()鐨勭粨鏋滅浉鍚屻

鏈嶅姟鍣ㄥ皢character_set_system绯荤粺鍙橀噺璁剧疆涓哄厓鏁版嵁瀛楃闆嗙殑鍚嶏細

mysql> SHOW VARIABLES LIKE 'character_set_system';
+----------------------+-------+
| Variable_name        | Value |
+----------------------+-------+
| character_set_system | utf8  |
+----------------------+-------+

瀛樺偍鍏冩暟鎹娇鐢Unicode骞朵笉鎰忓懗鐫鍒楀ご鍜DESCRIBE鍑芥暟鐨勭粨鏋滈粯璁ゅ湪character_set_system瀛楃闆嗕腑銆傚綋浣犱娇鐢SELECT column1 FROM t璇彞鏃讹紝鍚嶅瓧涓column1鐨勫垪浠庢湇鍔″櫒杩斿洖瀹㈡埛绔苟浣跨敤鐢SET NAMES璇彞纭畾鐨勫瓧绗﹂泦銆傛洿鏄庣‘鍦拌锛屼娇鐢ㄧ殑瀛楃闆嗘槸鐢character_set_results绯荤粺鍙橀噺鐨勫肩‘瀹氱殑銆傚鏋滆繖涓郴缁熷彉閲忚缃负NULL锛屼笉鎵ц瀛楃杞崲锛屾湇鍔″櫒浣跨敤鏈鍒濈殑瀛楃闆嗭紙瀛楃闆嗙敱character_set_system绯荤粺鍙橀噺璁剧疆锛夎繑鍥炲厓鏁版嵁銆

濡傛灉浣犲笇鏈涙湇鍔″櫒涓嶄娇鐢UTF8瀛楃闆嗚繑鍥炲厓鏁版嵁缁撴灉锛岄偅涔堜娇鐢SET NAMES璇彞寮哄埗鏈嶅姟鍣ㄦ墽琛屽瓧绗﹂泦杞崲锛堣10.3.6鑺傦紝鈥滆繛鎺ュ瓧绗﹂泦鍜屾牎瀵光锛夛紝鎴栬呭湪瀹㈡埛绔墽琛岃浆鎹€傚湪瀹㈡埛绔墽琛岃浆鎹㈡晥鐜囪緝楂橈紝浣嗚繖绉嶉夐」骞朵笉鑳戒娇鐢ㄤ簬鍏ㄩ儴瀹㈡埛绔

濡傛灉浣犳鍦ㄤ竴涓鍙ヤ腑浣跨敤锛堜緥濡傦級USER()鍑芥暟杩涜姣旇緝鎴栬祴鍊硷紝涓嶈鎷呭績銆MySQL涓轰綘鎵ц涓浜涘師瀛愯浆鎹€

SELECT * FROM Table1 WHERE USER() = latin1_column;

杩欐槸鍙互鐨勶紝鍥犱负鍦ㄦ瘮杈冧箣鍓latin1_column鍒楃殑鍐呭浼氳嚜鍔ㄨ浆鎹㈠埌UTF8

INSERT INTO Table1 (latin1_column) SELECT USER();

杩欐槸鍙互鐨勶紝鍥犱负璧嬪间箣鍓USER()鍑芥暟杩斿洖鐨勫唴瀹硅嚜鍔ㄨ浆鎹负latin1銆傝嚦浠婏紝鑷姩杞崲娌℃湁鍏ㄩ儴瀹炴柦锛屼絾鏄互鍚庣殑鐗堟湰涓簲璇ュ伐浣滄甯搞

灏界鑷姩杞崲涓嶅睘浜SQL鏍囧噯锛SQL鏍囧噯鍖栨枃妗d腑璇存瘡涓涓瓧绗﹂泦鏄紙鏍规嵁鏀寔鐨勫瓧绗︼級Unicode鐨勨瀛愰泦鈥濄傚洜姝わ紝涓涓煡鍚嶇殑鍘熷垯鏄紝鈥滈傜敤瓒呴泦鐨勫瓧绗﹂泦鑳藉搴旂敤浜庡叾瀛愰泦鈥濓紝鎴戜滑鐩镐俊Unicode鐨 鏍″瑙勫垯鑳藉搴旂敤浜庨潪Unicode瀛楃涓茬殑姣旇緝銆

娉ㄩ噴锛氬湪MySQL5.1涓紝errmsg.txt鏂囦欢鍏ㄩ儴浣跨敤UTF8銆傚鎴风瀛楃闆嗙殑杞崲鏄嚜鍔ㄨ繘琛岀殑锛屽鍚屽厓鏁版嵁銆

10.7. 涓庡叾瀹僁BMS鐨勫吋瀹规

瀵逛簬MaxDB鍏煎鎬э紝涓嬮潰涓や釜璇彞鏄浉鍚岀殑锛

CREATE TABLE t1 (f1 CHAR(n) UNICODE);
CREATE TABLE t1 (f1 CHAR(n) CHARACTER SET ucs2);

10.8. 鏂板瓧绗﹂泦閰嶇疆鏂囦欢鏍煎紡

瀛楃闆嗛厤缃瓨鍌ㄥ湪XML鏂囦欢涓紝涓涓瓧绗﹂泦瀵瑰簲涓涓枃浠躲

10.9. 鍥藉鐗规湁瀛楃闆

ANSI SQL瀹氫箟浜NCHAR鎴栬NATIONAL CHAR浣滀负涓涓柟娉曟潵鎸囩ずCHAR绫诲瀷鐨勫垪搴旇浣跨敤鏌愪簺棰勫畾涔夌殑瀛楃闆嗐MySQL5.1浣跨敤utf8浣滀负棰勫畾涔夌殑瀛楃闆嗐備緥濡傦紝杩欎簺鍒楃被鍨嬪0鏄庢槸绛変环鐨勶細
CHAR(10) CHARACTER SET utf8
NATIONAL CHARACTER(10)
NCHAR(10)

涓嬮潰鍚屾牱锛

VARCHAR(10) CHARACTER SET utf8
NATIONAL VARCHAR(10)
NCHAR VARCHAR(10)
NATIONAL CHARACTER VARYING(10)
NATIONAL CHAR VARYING(10)

浣犺兘澶熶娇鐢N'literal'鏉ュ垱寤轰竴涓娇鐢ㄥ浗瀹剁壒鏈夊瓧绗﹂泦鐨勫瓧绗︿覆銆傝繖涓や釜璇彞鏄瓑浠风殑锛

SELECT N'some text';
SELECT _utf8'some text';

鍏充簬MySQL4.1浠ュ墠鐨勭増鏈埌5.1鐗堟湰瀛楃闆嗗崌绾х殑淇℃伅锛岃鍙傝MySQL4.1鍙傝冩墜鍐

10.10. MySQL鏀寔鐨勫瓧绗﹂泦鍜屾牎瀵

MySQL鏀寔30澶氱瀛楃闆嗙殑70澶氱 鏍″瑙勫垯銆傚瓧绗﹂泦鍜屽畠浠殑榛樿鏍″瑙勫垯鍙互閫氳繃SHOW CHARACTER SET璇彞鏄剧ず锛

mysql> SHOW CHARACTER SET;
+----------+-----------------------------+---------------------+
| Charset  | Description                 | Default collation   |
+----------+-----------------------------+---------------------+
| big5     | Big5 Traditional Chinese    | big5_chinese_ci     |
| dec8     | DEC West European           | dec8_swedish_ci     |
| cp850    | DOS West European           | cp850_general_ci    |
| hp8      | HP West European            | hp8_english_ci      |
| koi8r    | KOI8-R Relcom Russian       | koi8r_general_ci    |
| latin1   | cp1252 West European        | latin1_swedish_ci   |
| latin2   | ISO 8859-2 Central European | latin2_general_ci   |
| swe7     | 7bit Swedish                | swe7_swedish_ci     |
| ascii    | US ASCII                    | ascii_general_ci    |
| ujis     | EUC-JP Japanese             | ujis_japanese_ci    |
| sjis     | Shift-JIS Japanese          | sjis_japanese_ci    |
| hebrew   | ISO 8859-8 Hebrew           | hebrew_general_ci   |
| tis620   | TIS620 Thai                 | tis620_thai_ci      |
| euckr    | EUC-KR Korean               | euckr_korean_ci     |
| koi8u    | KOI8-U Ukrainian            | koi8u_general_ci    |
| gb2312   | GB2312 Simplified Chinese   | gb2312_chinese_ci   |
| greek    | ISO 8859-7 Greek            | greek_general_ci    |
| cp1250   | Windows Central European    | cp1250_general_ci   |
| gbk      | GBK Simplified Chinese      | gbk_chinese_ci      |
| latin5   | ISO 8859-9 Turkish          | latin5_turkish_ci   |
| armscii8 | ARMSCII-8 Armenian          | armscii8_general_ci |
| utf8     | UTF-8 Unicode               | utf8_general_ci     |
| ucs2     | UCS-2 Unicode               | ucs2_general_ci     |
| cp866    | DOS Russian                 | cp866_general_ci    |
| keybcs2  | DOS Kamenicky Czech-Slovak  | keybcs2_general_ci  |
| macce    | Mac Central European        | macce_general_ci    |
| macroman | Mac West European           | macroman_general_ci |
| cp852    | DOS Central European        | cp852_general_ci    |
| latin7   | ISO 8859-13 Baltic          | latin7_general_ci   |
| cp1251   | Windows Cyrillic            | cp1251_general_ci   |
| cp1256   | Windows Arabic              | cp1256_general_ci   |
| cp1257   | Windows Baltic              | cp1257_general_ci   |
| binary   | Binary pseudo charset       | binary              |
| geostd8  | GEOSTD8 Georgian            | geostd8_general_ci  |
| cp932    | SJIS for Windows Japanese   | cp932_japanese_ci   |
| eucjpms  | UJIS for Windows Japanese   | eucjpms_japanese_ci |
+----------+-----------------------------+---------------------+

10.10.1. Unicode瀛楃闆

MySQL鏈変袱绉Unicode瀛楃闆嗐備綘鑳藉浣跨敤杩欎簺瀛楃闆嗕繚瀛樺ぇ绾650绉嶈瑷鐨勬枃鏈

         ucs2 (UCS-2 Unicode)鏍″瑙勫垯:

  • mysql> SHOW COLLATION LIKE 'ucs2%';
    +--------------------+---------+-----+---------+----------+---------+
    | Collation          | Charset | Id  | Default | Compiled | Sortlen |
    +--------------------+---------+-----+---------+----------+---------+
    | ucs2_general_ci    | ucs2    |  35 | Yes     | Yes      |       1 |
    | ucs2_bin           | ucs2    |  90 |         | Yes      |       1 |
    | ucs2_unicode_ci    | ucs2    | 128 |         | Yes      |       8 |
    | ucs2_icelandic_ci  | ucs2    | 129 |         | Yes      |       8 |
    | ucs2_latvian_ci    | ucs2    | 130 |         | Yes      |       8 |
    | ucs2_romanian_ci   | ucs2    | 131 |         | Yes      |       8 |
    | ucs2_slovenian_ci  | ucs2    | 132 |         | Yes      |       8 |
    | ucs2_polish_ci     | ucs2    | 133 |         | Yes      |       8 |
    | ucs2_estonian_ci   | ucs2    | 134 |         | Yes      |       8 |
    | ucs2_spanish_ci    | ucs2    | 135 |         | Yes      |       8 |
    | ucs2_swedish_ci    | ucs2    | 136 |         | Yes      |       8 |
    | ucs2_turkish_ci    | ucs2    | 137 |         | Yes      |       8 |
    | ucs2_czech_ci      | ucs2    | 138 |         | Yes      |       8 |
    | ucs2_danish_ci     | ucs2    | 139 |         | Yes      |       8 |
    | ucs2_lithuanian_ci | ucs2    | 140 |         | Yes      |       8 |
    | ucs2_slovak_ci     | ucs2    | 141 |         | Yes      |       8 |
    | ucs2_spanish2_ci   | ucs2    | 142 |         | Yes      |       8 |
    | ucs2_roman_ci      | ucs2    | 143 |         | Yes      |       8 |
    | ucs2_persian_ci    | ucs2    | 144 |         | Yes      |       8 |
    | ucs2_esperanto_ci  | ucs2    | 145 |         | Yes      |       8 |
    +--------------------+---------+-----+---------+----------+---------+
    
  • utf8 (UTF-8 Unicode)鏍″瑙勫垯:

    mysql> SHOW COLLATION LIKE 'utf8%';
    +--------------------+---------+-----+---------+----------+---------+
    | Collation          | Charset | Id  | Default | Compiled | Sortlen |
    +--------------------+---------+-----+---------+----------+---------+
    | utf8_general_ci    | utf8    |  33 | Yes     | Yes      |       1 |
    | utf8_bin           | utf8    |  83 |         | Yes      |       1 |
    | utf8_unicode_ci    | utf8    | 192 |         | Yes      |       8 |
    | utf8_icelandic_ci  | utf8    | 193 |         | Yes      |       8 |
    | utf8_latvian_ci    | utf8    | 194 |         | Yes      |       8 |
    | utf8_romanian_ci   | utf8    | 195 |         | Yes      |       8 |
    | utf8_slovenian_ci  | utf8    | 196 |         | Yes      |       8 |
    | utf8_polish_ci     | utf8    | 197 |         | Yes      |       8 |
    | utf8_estonian_ci   | utf8    | 198 |         | Yes      |       8 |
    | utf8_spanish_ci    | utf8    | 199 |         | Yes      |       8 |
    | utf8_swedish_ci    | utf8    | 200 |         | Yes      |       8 |
    | utf8_turkish_ci    | utf8    | 201 |         | Yes      |       8 |
    | utf8_czech_ci      | utf8    | 202 |         | Yes      |       8 |
    | utf8_danish_ci     | utf8    | 203 |         | Yes      |       8 |
    | utf8_lithuanian_ci | utf8    | 204 |         | Yes      |       8 |
    | utf8_slovak_ci     | utf8    | 205 |         | Yes      |       8 |
    | utf8_spanish2_ci   | utf8    | 206 |         | Yes      |       8 |
    | utf8_roman_ci      | utf8    | 207 |         | Yes      |       8 |
    | utf8_persian_ci    | utf8    | 208 |         | Yes      |       8 |
    | utf8_esperanto_ci  | utf8    | 209 |         | Yes      |       8 |
    +--------------------+---------+-----+---------+----------+---------+
    

utf8_unicode_ci鏍″瑙勫垯鏄牴鎹Unicode鏍″瑙勫垯绠楁硶锛UCA锛夋墽琛岀殑锛 鏍″瑙勫垯鎻忚堪瑙 http://www.unicode.org/reports/tr10/銆傛鏍″瑙勫垯浣跨敤UCA 4.0.0鐗堟湰鐮濈爜閿細http://www.unicode.org/Public/UC涓涓/4.0.0/涓涓llkeys-4.0.0.txt銆傦紙浠ヤ笅璁ㄨ浣跨敤utf8_unicode_ci锛屼絾鍚屾牱閫傚悎ucs2_unicode_ci銆傦級

褰撳墠锛utf8_unicode_ci鏍″瑙勫垯浠呴儴鍒嗘敮鎸Unicode鏍″瑙勫垯绠楁硶銆備竴浜涘瓧绗﹁繕鏄笉鑳芥敮鎸併傚苟涓旓紝涓嶈兘瀹屽叏鏀寔缁勫悎鐨勮鍙枫傝繖涓昏褰卞搷瓒婂崡鍜屼縿缃楁柉鐨勪竴浜涘皯鏁版皯鏃忚瑷锛屽锛Udmurt TatarBashkirMari

utf8_unicode_ci鐨勬渶涓昏鐨勭壒鑹叉槸鏀寔鎵╁睍锛屽嵆褰撴妸涓涓瓧姣嶇湅浣滀笌鍏跺畠瀛楁瘝缁勫悎鐩哥瓑鏃躲備緥濡傦紝鍦ㄥ痉璇拰涓浜涘叾瀹冭瑷涓鈥欑瓑浜庘ss鈥欍

utf8_general_ci鏄竴涓仐鐣欑殑 鏍″瑙勫垯锛屼笉鏀寔鎵╁睍銆傚畠浠呰兘澶熷湪瀛楃涔嬮棿杩涜閫愪釜姣旇緝銆傝繖鎰忓懗鐫utf8_general_ci鏍″瑙勫垯杩涜鐨勬瘮杈冮熷害寰堝揩锛屼絾鏄笌浣跨敤utf8_unicode_ci鐨 鏍″瑙勫垯鐩告瘮锛屾瘮杈冩纭ц緝宸級銆

渚嬪锛屼娇鐢utf8_general_ciutf8_unicode_ci涓ょ 鏍″瑙勫垯涓嬮潰鐨勬瘮杈冪浉绛夛細

 = A
 = O
 = U

涓ょ鏍″瑙勫垯涔嬮棿鐨勫尯鍒槸锛屽浜utf8_general_ci涓嬮潰鐨勭瓑寮忔垚绔嬶細

 = s

浣嗘槸锛屽浜utf8_unicode_ci涓嬮潰绛夊紡鎴愮珛锛

 = ss

瀵逛簬涓绉嶈瑷浠呭綋浣跨敤utf8_unicode_ci鎺掑簭鍋氱殑涓嶅ソ鏃讹紝鎵嶆墽琛屼笌鍏蜂綋璇█鐩稿叧鐨utf8瀛楃闆 鏍″瑙勫垯銆備緥濡傦紝瀵逛簬寰疯鍜屾硶璇紝utf8_unicode_ci宸ヤ綔鐨勫緢濂斤紝鍥犳涓嶅啀闇瑕佷负杩欎袱绉嶈瑷鍒涘缓鐗规畩鐨utf8鏍″瑙勫垯銆

utf8_general_ci涔熼傜敤涓庡痉璇拰娉曡锛岄櫎浜嗏鈥欑瓑浜庘s鈥欙紝鑰屼笉鏄ss鈥欎箣澶栥傚鏋滀綘鐨勫簲鐢ㄨ兘澶熸帴鍙楄繖浜涳紝閭d箞搴旇浣跨敤utf8_general_ci鍥犱负瀹冮熷害蹇傚惁鍒欙紝浣跨敤utf8_unicode_ci锛屽洜涓哄畠姣旇緝鍑嗙‘銆

utf8_swedish_ci锛屼笌鍏跺畠璇█鐩稿叧鐨utf8鐨勬牎瀵硅鍒欑浉浼硷紝鏉ユ簮浜utf8_unicode_ci浣跨敤棰濆鐨勮瑷瑙勫垯銆備緥濡傦紝鍦ㄧ憺鍏歌涓紝浠ヤ笅鐨勫叧绯诲紡鎴愮珛锛屽畠鍦ㄥ痉璇拰娉曡涓笉鎴愮珛锛

 = Y < 

utf8_spanish_ciutf8_spanish2_ci鏍″瑙勫垯鍒嗗埆閫傜敤浜庣幇浠e拰鍙ゅ吀瑗跨彮鐗欒銆傚湪涓ょ 鏍″瑙勫垯涓紝鈥欙紙n-鍙戦煶绗︼級鏄n鈥欏拰鈥o鈥欎箣闂寸殑闂撮殧瀛楁瘝銆傚彟澶栵紝瀵逛簬鍙ゅ吀瑗跨彮鐗欒锛屸ch鈥欐槸鈥c鈥欏拰d涔嬮棿鐨勯棿闅斿瓧姣嶏紝骞朵笖鈥ll鈥欐槸鈥l鈥欏拰鈥m鈥欎箣闂寸殑闂撮殧瀛楁瘝銆

10.10.2. 瑗挎瀛楃闆

瑗挎瀛楃闆嗚鐩栧ぇ澶氭暟瑗挎璇█锛屽娉曡銆佽タ鐝墮璇佸姞娉扮綏灏间簹璇佸反鏂厠浜鸿銆佽憽钀勭墮璇佹剰澶у埄璇侀樋鑰屽反灏间簹璇佽嵎鍏拌銆佸痉璇佷腹楹﹁銆佺憺鍏歌銆佹尓濞佽銆佽姮鍏拌銆佹硶缃椾汉璇佸啺宀涜銆佺埍灏斿叞璇佽嫃鏍煎叞璇拰鑻辫銆

         asciiUS ASCII锛夋牎瀵硅鍒欙細

o        ascii_bin

o        ascii_general_ci锛 榛樿锛

         cp850DOS瑗挎锛 鏍″瑙勫垯锛

o        cp850_bin

o        cp850_general_ci锛 榛樿锛

         dec8DEC 瑗挎锛夋牎瀵硅鍒欙細

o        dec8_bin

o        dec8_swedish_ci锛 榛樿锛

         hp8HP 瑗挎锛夋牎瀵硅鍒欙細

o        hp8_bin

o        hp8_english_ci锛 榛樿锛

         latin1cp1252 瑗挎锛夋牎瀵硅鍒欙細

o        latin1_bin

o        latin1_danish_ci

o        latin1_general_ci

o        latin1_general_cs

o        latin1_german1_ci

o        latin1_german2_ci

o        latin1_spanish_ci

o        latin1_swedish_ci锛 榛樿锛

latin1鏄 榛樿瀛楃闆嗐latin1_swedish_ci鏄 榛樿鐨勬牎瀵硅鍒欙紝瀹冪敤浜庡ぇ澶氭暟MySQL瀹㈡埛銆傝櫧鐒剁粡甯歌瀹冧互鐟炲吀/鑺叞 鏍″瑙勫垯涓哄熀纭锛屼絾鐟炲吀鍜岃姮鍏颁汉涓嶅悓鎰忚繖绉嶈娉曘

latin1_german1_cilatin1_german2_ci鏍″瑙勫垯鍩轰簬DIN-1DIN-2鏍囧噯锛岃繖閲DIN浠h〃Deutsches Institut fr Normung锛堝痉璇瓑浠蜂簬ANSI锛夈DIN-1琚彨鍋氣瀛楀吀鏍″瑙勫垯鈥濓紝DIN-2琚彨鍋氣鐢佃瘽绨挎牎瀵硅鍒鈥濄

o        latin1_german1_ci锛堝瓧鍏革級瑙勫垯锛

o                      = a
o                      = O
o                      = U
o                      = s

o        latin1_german2_ci鐢佃瘽绨锛夎鍒欙細

o                      = aE
o                      = OE
o                      = UE
o                      = ss

latin1_spanish_ci鏍″瑙勫垯涓紝鈥鈥欙紙n-tilde锛夋槸鈥n鈥欏拰鈥o鈥欎箣闂寸殑闂撮殧瀛楁瘝銆

         macromaMac瑗挎锛 鏍″瑙勫垯锛

o        macroman_bin

o        macroman_general_ci锛 榛樿锛

         swe77浣嶇憺鍏歌锛 鏍″瑙勫垯锛

o        swe7_bin

o        swe7_swedish_ci锛 榛樿锛

10.10.3. 涓瀛楃闆

鎴戜滑杩樻彁渚涗竴浜涚敤浜庢嵎鍏嬪叡鍜屽浗銆佹柉娲涗紣鍏嬨佸寛鐗欏埄銆佺綏椹凹浜氥佹柉缃楃汗灏间簹銆佸厠缃楀湴浜氬拰娉㈠叞鐨勫瓧绗﹂泦鏀寔銆

         cp1250Windows涓锛 鏍″瑙勫垯锛

o        cp1250_bin

o        cp1250_croatian_ci

o        cp1250_czech_cs

o        cp1250_general_ci锛 榛樿锛

         cp852DOS 涓锛夋牎瀵硅鍒欙細

o        cp852_bin

o        cp852_general_ci锛 榛樿锛

         keybcs2DOS Kamenicky Czech-Slovak锛夋牎瀵硅鍒欙細

o        keybcs2_bin

o        keybcs2_general_ci锛 榛樿锛

         latin2ISO 8859-2 涓锛夋牎瀵硅鍒欙細

o        latin2_bin

o        latin2_croatian_ci

o        latin2_czech_cs

o        latin2_general_ci锛 榛樿锛

o        latin2_hungarian_ci

         macceMac 涓锛夋牎瀵硅鍒欙細

o        macce_bin

o        macce_general_ci锛 榛樿锛

10.10.4. 鍗楁涓庝腑涓滃瓧绗﹂泦

MySQL鏀寔鐨勫崡娆у拰涓笢瀛楃闆嗗寘鎷簹缇庡凹浜氳銆侀樋鎷変集璇佷箶娌讳簹璇佸笇鑵婅銆佸笇浼幈璇拰鍦熻冲叾璇細

         armscii8ARMSCII-8 浜氱編灏间簹璇級鏍″瑙勫垯锛

o        armscii8_bin

o        armscii8_general_ci锛 榛樿锛

         cp1256锛堥樋鎷変集璇Windows锛 鏍″瑙勫垯锛

o        cp1256_bin

o        cp1256_general_ci锛 榛樿锛

         geostd8GEOSTD8涔旀不浜氳锛 鏍″瑙勫垯锛

o        geostd8_bin

o        geostd8_general_ci锛 榛樿锛

         greekISO 8859-7甯岃厞璇級鏍″瑙勫垯锛

o        greek_bin

o        greek_general_ci锛 榛樿锛

         hebrewISO 8859-8甯屼集鑾辫锛夋牎瀵硅鍒欙細

o        hebrew_bin

o        hebrew_general_ci锛 榛樿锛

         latin5ISO 8859-9 鍦熻冲叾璇級鏍″瑙勫垯锛

o        latin5_bin

o        latin5_turkish_ci锛 榛樿锛

10.10.5. 娉㈢綏鐨勬捣瀛楃闆

娉㈢綏鐨勬捣瀛楃闆嗚鐩栫埍娌欏凹浜氳銆佹媺鑴辩淮浜氳鍜岀珛闄跺疀璇█銆傚綋鍓嶆敮鎸佺殑涓ょ娉㈢綏鐨勬捣瀛楃闆嗭細

         cp1257Windows娉㈢綏鐨勬捣锛 鏍″瑙勫垯锛

o        cp1257_bin

o        cp1257_general_ci锛 榛樿锛

o        cp1257_lithuanian_ci

         latin7ISO 8859-13娉㈢綏鐨勬捣锛夋牎瀵硅鍒欙細

o        latin7_bin

o        latin7_estonian_cs

o        latin7_general_ci锛 榛樿锛

o        latin7_general_cs

10.10.6. 瑗块噷灏斿瓧绗﹂泦

浣跨敤瑗块噷灏斿瓧绗﹂泦鍜屾牎瀵硅鍒欑殑鏈Belarusian銆佷繚鍔犲埄浜氥佷縿璇拰涔屽厠鍏拌瑷銆

         cp1251Windows 瑗块噷灏旓級鏍″瑙勫垯锛

o        cp1251_bin

o        cp1251_bulgarian_ci

o        cp1251_general_ci锛 榛樿锛

o        cp1251_general_cs

o        cp1251_ukrainian_ci

         cp866DOS 淇勮锛夋牎瀵硅鍒欙細

o        cp866_bin

o        cp866_general_ci锛 榛樿锛

         koi8rKOI8-R Relcom 淇勮锛夋牎瀵硅鍒欙細

o        koi8r_bin

o        koi8r_general_ci锛 榛樿锛

         koi8uKOI8-U 涔屽厠鍏拌锛夋牎瀵硅鍒欙細

o        koi8u_bin

o        koi8u_general_ci锛 榛樿锛

10.10.7. 浜氭床瀛楃闆

鎴戜滑鏀寔鐨勪簹娲插瓧绗﹂泦鍖呮嫭涓枃銆佹棩璇侀煩璇拰娉板浗璇傝繖浜涘彲鑳芥瘮杈冨鏉傘備緥濡傦紝涓枃瀛楃闆嗗繀椤昏冭檻鍒颁笂鍗冪涓嶅悓鐨勫瓧绗︺

         big5Big5浼犵粺涓枃锛 鏍″瑙勫垯锛

o        big5_bin

o        big5_chinese_ci锛 榛樿锛

         cp932SJIS Windows鏃ヨ锛夋牎瀵硅鍒欙細

o        cp932_bin

o        cp932_japanese_ci锛 榛樿锛

         eucjpmsUJIS Windows鏃ヨ锛夋牎瀵硅鍒欙細

o        eucjpms_bin

o        eucjpms_japanese_ci锛 榛樿锛

         euckrEUC-KR 闊╄锛夋牎瀵硅鍒欙細

o        euckr_bin

o        euckr_korean_ci锛 榛樿锛

         gb2312GB2312 绠浣撲腑鏂囷級鏍″瑙勫垯锛

o        gb2312_bin

o        gb2312_chinese_ci锛 榛樿锛

         gbkGBK绠浣撲腑鏂囷級 鏍″瑙勫垯锛

o        gbk_bin

o        gbk_chinese_ci锛 榛樿锛

         sjisShift-JIS 鏃ヨ锛夋牎瀵硅鍒欙細

o        sjis_bin

o        sjis_japanese_ci锛 榛樿锛

         tis620TIS620 娉板浗璇級鏍″瑙勫垯锛

o        tis620_bin

o        tis620_thai_ci锛 榛樿锛

         ujisEUC-JP 鏃ヨ锛夋牎瀵硅鍒欙細

o        ujis_bin

o        ujis_japanese_ci锛 榛樿锛

10.10.7.1. cp932瀛楃闆

涓轰粈涔堥渶瑕cp932

MySQL涓紝sjis瀛楃闆嗗搴斾簬鐢IANA瀹氫箟鐨Shift_JIS瀛楃闆嗭紝瀹冩敮鎸JIS X0201JIS X0208瀛楃銆傦紙瑙 http://www.iana.org/assignments/character-sets銆傦級

浣嗘槸锛屸SHIFT JIS鈥濅綔涓烘弿杩版ф湳璇殑鍚箟鍙樺緱闈炲父鍚硦涓嶆竻锛屽苟涓斿畠甯稿父鍖呮嫭鐢变笉鍚屼緵搴斿晢瀹氫箟鐨Shift_JIS鎵╁睍閮ㄥ垎銆

渚嬪锛屼娇鐢ㄥ湪鏃ユ湰Windows鐜涓娇鐢ㄧ殑鈥SHIFT JIS鈥濇槸MicrosoftShift_JISMicrosoft鎵╁睍锛屽畠鐨勫噯纭悕瀛楁槸Microsoft Windows Codepage: 932cp932闄ょ敱Shift_JIS鏀寔鐨勫瓧绗︿箣澶栵紝cp932鏀寔鎵╁睍瀛楃锛屽NEC閫夋嫨鐨IBM鎵╁睍瀛楃鍜IBM鎵╁睍瀛楃銆

璁稿鏃ユ湰鐢ㄦ埛鍦ㄤ娇鐢ㄨ繖浜涙墿灞曞瓧绗﹁繃绋嬩腑纰板埌杩囦竴浜涢棶棰樸傝繖浜涢棶棰樻槸鐢变簬浠ヤ笅鎯呭喌寮曡捣鐨勶細

         MySQL鑷姩杞崲瀛楃闆嗐

         瀛楃闆嗛氳繃Unicode杞崲锛ucs2锛夈

         sjis瀛楃闆嗕笉鏀寔杩欎簺鎵╁睍瀛楃杞崲銆

         浠庡彿绉扳SHIFT JIS鈥濆埌Unicode鐨勮浆鎹紝瀛樺湪涓浜涜浆鎹㈣鍒欙紝骞朵笖涓浜涘瓧绗﹁浆鎹㈠埌Unicode渚濊禆涓嶅悓鐨勮浆鎹㈣鍒欍MySQL浠呮敮鎸佽繖浜涜浆鎹㈣鍒欎腑鐨勪竴绉嶏紙鍦ㄥ悗闈㈡弿杩帮級銆

MySQLcp932瀛楃闆嗗彲浠ヨВ鍐宠繖浜涜浆鎹㈤棶棰樸

鍥犱负MySQL鏀寔瀛楃闆嗚浆鎹紝灏IANA Shift_JIS cp932鍒嗙涓轰袱绉嶄笉鍚屽瓧绗﹂泦鏄噸瑕佺殑锛屽洜涓哄畠浠彁渚涗笉鍚岀殑杞崲瑙勫垯銆

cp932sjis鏈変粈涔堜笉鍚岋紵

cp932瀛楃闆嗕笌sjis瀛樺湪浠ヤ笅涓嶅悓鐐癸細

         cp932鏀寔NEC鐗规畩瀛楃銆NEC閫夋嫨鐨IBM鎵╁睍瀛楃鍜IBM閫夋嫨鐨勫瓧绗︺

         涓浜cp932瀛楃鏈変袱涓笉鍚岀殑缂栫爜鐐癸紝杩欎袱绉嶇紪鐮佺偣杞崲涓虹浉鍚Unicode缂栫爜鐐广傚洜姝わ紝褰撲粠Unicode杞崲鍥炲埌cp932鏃讹紝蹇呴』閫夋嫨涓涓紪鐮佺偣銆傚浜庤繖绉嶁滅浉浜杞崲浣跨敤鐢Microsoft鎺ㄨ崘鐨勮浆鎹㈣鍒欍傦紙瑙 http//support.microsoft.com/kb/170559/EN-US/銆傦級

杞崲瑙勫垯濡備笅锛

o        濡傛灉瀛楃鍦JIS X 0208 NEC鐗规畩瀛楃涓悓鏃跺瓨鍦紝浣跨敤JIS X 0208 鐨勭紪鐮佺偣銆

o        濡傛灉瀛楃鍦NEC鐗规畩瀛楃鍜IBM閫夋嫨鐨勫瓧绗︿腑鍚屾椂瀛樺湪锛屼娇鐢NEC鐗规畩瀛楃鐨勭紪鐮佺偣銆

o        濡傛灉瀛楃鍦IBM閫夋嫨鐨勫瓧绗﹀拰NEC閫夋嫨鐨IBM鎵╁睍瀛楃涓悓鏃跺瓨鍦紝浣跨敤IBM鎵╁睍瀛楃鐨勭紪鐮佺偣銆

鍏充簬cp932瀛楃鐨Unicode 鍊肩殑鍒楄〃鏄剧ず淇℃伅瑙http://www.microsoft.com/globaldev/reference/dbcs/932.htm銆傚浜cp932琛ㄤ腑鐨勫甫鏈変笅闈㈡湁鍥涗綅鏁板瓧鍑虹幇鐨勫瓧绗︾殑瀹炰綋锛屾暟瀛椾唬琛ㄧ浉搴旂殑Unicodeucs2锛夌紪鐮併傚浜庤〃涓湁涓や釜甯︿笅鍒掔嚎鐨勬暟瀛楀嚭鐜扮殑瀹炰綋锛屾嫨鏈変竴涓互閭d袱涓暟瀛楀紑澶寸殑cp932瀛楃鍊肩殑鑼冨洿銆傜偣鍑讳竴涓繖绉嶈〃鐨勫疄浣擄紝灏嗗甫浣犲埌涓涓〉锛岃椤垫樉绀烘瘡涓互閭d簺鏁板瓧寮澶寸殑cp932瀛楃鐨Unicode鍊笺

浠ヤ笅杩炴帴寰堥噸瑕併傚畠浠笌涓嬪垪瀛楃闆嗙殑缂栫爜鐩稿搴旓細

o        NEC鐗规畩瀛楃锛

http://www.microsoft.com/globaldev/reference/dbcs/932/932_87.htm

o        NEC閫夋嫨鐨IBM鎵╁睍瀛楃锛

o                     http://www.microsoft.com/globaldev/reference/dbcs/932/932_ED.htm
o                     http://www.microsoft.com/globaldev/reference/dbcs/932/932_EE.htm

o        IBM閫夋嫨鐨勫瓧绗︼細

o                     http://www.microsoft.com/globaldev/reference/dbcs/932/932_FA.htm
o                     http://www.microsoft.com/globaldev/reference/dbcs/932/932_FB.htm
o                     http://www.microsoft.com/globaldev/reference/dbcs/932/932_FC.htm

         cp932eucjpms缁撳悎鏀寔鐢ㄦ埛鑷畾涔夊瓧绗︾殑杞崲锛屽苟涓旇В鍐sjis/ujis杞崲闂銆傝缁嗕俊鎭紝璇峰弬瑙http://www.opengroup.or.jp/jvc/cde/sjis-euc-e.html

         瀵逛簬涓浜涘瓧绗︼紝涓ucs2涔嬮棿鐨勮浆鎹笌sjiscp932涔嬮棿鐨勮浆鎹㈡槸涓嶅悓鐨勩備笅琛ㄤ妇渚嬭鏄庝簡杩欎簺涓嶅悓銆

杞崲鍒ucs2

sjis/cp932

sjis ucs2杞崲

cp932 ucs2杞崲

5C

005C

005C

7E

007E

007E

815C

2015

2015

815F

005C

FF3C

8160

301C

FF5E

8161

2016

2225

817C

2212

FF0D

8191

00a2

FFE0

8192

00a3

FFE1

81Ca

00aC

FFE2

ucs2杞崲锛

ucs2

ucs2 sjis杞崲

ucs2 cp932杞崲

005C

815F

5C

007E

7E

7E

00a2

8191

3F

00a3

8192

3F

00aC

81Ca

3F

2015

815C

815C

2016

8161

3F

2212

817C

3F

2225

3F

8161

301C

8160

3F

FF0D

3F

817C

FF3C

3F

815F

FF5E

3F

8160

FFE0

3F

8191

FFE1

3F

8192

FFE2

3F

81Ca


杩欐槸MySQL鍙傝冩墜鍐岀殑缈昏瘧鐗堟湰锛屽叧浜嶮ySQL鍙傝冩墜鍐岋紝璇疯闂dev.mysql.com銆 鍘熷鍙傝冩墜鍐屼负鑻辨枃鐗堬紝涓庤嫳鏂囩増鍙傝冩墜鍐岀浉姣旓紝鏈炕璇戠増鍙兘涓嶆槸鏈鏂扮殑銆