10.2.MySQL中的字符集和校對
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節,“MySQL支持的字符集和校對”。)
任何一個給定的字符集至少有一個校對規則。它可能有幾個校對規則。
要想列出一個字符集的校對規則,使用SHOW COLLATION語句。例如,要想查看latin1(“西歐ISO-8859-1”)字符集的 校對規則,使用下面的語句查找那些名字以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(二元)結束。