MySQL 排序规则名称遵循以下约定:MySQL collation names follow these conventions:
排序规则名称以其相关的字符集名称开头,通常后面跟一个或多个后缀以指示其他排序规则特性。例如,
utf8mb4_0900_ai_ci和latin1_swedish_ci分别是utf8mb4和latin1字符集的排序规则。binary字符集只有一个排序规则,也名为binary,没有后缀。A collation name starts with the name of the character set with which it is associated, generally followed by one or more suffixes indicating other collation characteristics. For example,utf8mb4_0900_ai_ciandlatin1_swedish_ciare collations for theutf8mb4andlatin1character sets, respectively. Thebinarycharacter set has a single collation, also namedbinary, with no suffixes.特定语言的排序规则包括一个地区代码或语言名称。例如,
utf8mb4_tr_0900_ai_ci和utf8mb4_hu_0900_ai_ci分别使用土耳其语和匈牙利语的规则对utf8mb4字符集的字符进行排序。utf8mb4_turkish_ci和utf8mb4_hungarian_ci类似,但基于更新版本的 Unicode 排序算法。A language-specific collation includes a locale code or language name. For example,utf8mb4_tr_0900_ai_ciandutf8mb4_hu_0900_ai_cisort characters for theutf8mb4character set using the rules of Turkish and Hungarian, respectively.utf8mb4_turkish_ciandutf8mb4_hungarian_ciare similar but based on a less recent version of the Unicode Collation Algorithm.排序规则后缀指示排序规则是否区分大小写、重音、假名(或它们的某种组合),或二进制。下表显示了用于指示这些特征的后缀。Collation suffixes indicate whether a collation is case-sensitive, accent-sensitive, or kana-sensitive (or some combination thereof), or binary. The following table shows the suffixes used to indicate these characteristics.
表 12.1 排序后缀含义Table 12.1 Collation Suffix Meanings
后缀Suffix 意义Meaning _ai不区分重音Accent-insensitive _as_as区分重音的Accent-sensitive _ci不区分大小写Case-insensitive _cs区分大小写Case-sensitive _ks假名敏感Kana-sensitive _bin二进制Binary 对于未指定重音敏感性的非二元排序规则名称,其重音敏感性由大小写敏感性决定。如果排序规则名称中不包含
_ai或_as,那么名称中的_ci表示_ai,名称中的_cs表示_as。例如,latin1_general_ci是明确大小写不敏感且隐含重音不敏感的,latin1_general_cs是明确大小写敏感且隐含重音敏感的,而utf8mb4_0900_ai_ci是明确大小写不敏感且重音不敏感的。For nonbinary collation names that do not specify accent sensitivity, it is determined by case sensitivity. If a collation name does not contain_aior_as,_ciin the name implies_aiand_csin the name implies_as. For example,latin1_general_ciis explicitly case-insensitive and implicitly accent-insensitive,latin1_general_csis explicitly case-sensitive and implicitly accent-sensitive, andutf8mb4_0900_ai_ciis explicitly case-insensitive and accent-insensitive.对于日语排序,
_ks后缀表示排序区分假名;也就是说,它区分片假名字符和平假名字符。没有_ks后缀的日语排序不区分假名,在排序时将片假名和平假名字符视为相等。For Japanese collations, the_kssuffix indicates that a collation is kana-sensitive; that is, it distinguishes Katakana characters from Hiragana characters. Japanese collations without the_kssuffix are not kana-sensitive and treat Katakana and Hiragana characters equal for sorting.对于
binary字符集的binary排序规则,比较基于数值字节值。对于非二进制字符集的_bin排序规则,比较基于数值字符代码值,对于多字节字符,这些值与字节值不同。有关binary字符集的binary排序规则与非二进制字符集的_bin排序规则之间差异的信息,请参见 第 12.8.5 节,“binary 排序规则与 _bin 排序规则的比较”。For thebinarycollation of thebinarycharacter set, comparisons are based on numeric byte values. For the_bincollation of a nonbinary character set, comparisons are based on numeric character code values, which differ from byte values for multibyte characters. For information about the differences between thebinarycollation of thebinarycharacter set and the_bincollations of nonbinary character sets, see Section 12.8.5, “The binary Collation Compared to _bin Collations”.Unicode 字符集的排序名称可能包含版本号,以指示排序所基于的 Unicode 排序算法 (UCA) 的版本。名称中没有版本号的基于 UCA 的排序使用版本 4.0.0 的 UCA 权重键。例如:Collation names for Unicode character sets may include a version number to indicate the version of the Unicode Collation Algorithm (UCA) on which the collation is based. UCA-based collations without a version number in the name use the version-4.0.0 UCA weight keys. For example:
utf8mb4_0900_ai_ci基于 UCA 9.0.0 权重键 (http://www.unicode.org/Public/UCA/9.0.0/allkeys.txt)。utf8mb4_0900_ai_ciis based on UCA 9.0.0 weight keys (http://www.unicode.org/Public/UCA/9.0.0/allkeys.txt).utf8mb4_unicode_520_ci基于 UCA 5.2.0 权重键 (http://www.unicode.org/Public/UCA/5.2.0/allkeys.txt)。utf8mb4_unicode_520_ciis based on UCA 5.2.0 weight keys (http://www.unicode.org/Public/UCA/5.2.0/allkeys.txt).utf8mb4_unicode_ci(未指定版本)基于 UCA 4.0.0 权重键 (http://www.unicode.org/Public/UCA/4.0.0/allkeys-4.0.0.txt)。utf8mb4_unicode_ci(with no version named) is based on UCA 4.0.0 weight keys (http://www.unicode.org/Public/UCA/4.0.0/allkeys-4.0.0.txt).
对于 Unicode 字符集,
排序规则保留了原始xxx_general_mysql500_ci排序规则在 5.1.24 之前的顺序,并允许升级在 MySQL 5.1.24 之前创建的表(Bug #27877)。For Unicode character sets, thexxx_general_cicollations preserve the pre-5.1.24 ordering of the originalxxx_general_mysql500_cicollations and permit upgrades for tables created before MySQL 5.1.24 (Bug #27877).xxx_general_ci