MySQL中的字符集和校对学习--MySql语法

2021-07-30 16:28:44 浏览数 (1)

MySQL服务器能够支持多种字符集。可以使用SHOW CHARACTER SET语句列出可用的字符集:

代码语言:javascript复制
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 |
...

任何一个给定的字符集至少有一个校对规则。它可能有几个校对规则。

要想列出一个字符集的校对规则,使用SHOW COLLATION语句。例如,要想查看latin1(“西欧ISO-8859-1”)字符集的 校对规则,使用下面的语句查找那些名字以latin1开头的 校对规则:

代码语言:javascript复制
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(二元)结束。

0 人点赞