文档首页
MySQL 8.4 参考手册
8.4 中文镜像

MySQL 8.4 参考手册 · 中文镜像

正文为中文,英文原文默认隐藏。点击任意中文段落即可展开 / 收起对应英文原文。

打开官方英文原文 ↗

译文由机器翻译生成,仅供理解参考;有疑问请以官方英文原文为准。

中文点击中文段落可显示 / 隐藏英文原文本页译文覆盖 82%

12.3.1 排序规则命名约定12.3.1 Collation Naming Conventions

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_ci and latin1_swedish_ci are collations for the utf8mb4 and latin1 character sets, respectively. The binary character set has a single collation, also named binary, 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_ci and utf8mb4_hu_0900_ai_ci sort characters for the utf8mb4 character set using the rules of Turkish and Hungarian, respectively. utf8mb4_turkish_ci and utf8mb4_hungarian_ci are 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 _ai or _as, _ci in the name implies _ai and _cs in the name implies _as. For example, latin1_general_ci is explicitly case-insensitive and implicitly accent-insensitive, latin1_general_cs is explicitly case-sensitive and implicitly accent-sensitive, and utf8mb4_0900_ai_ci is explicitly case-insensitive and accent-insensitive.

    对于日语排序,_ks 后缀表示排序区分假名;也就是说,它区分片假名字符和平假名字符。没有 _ks 后缀的日语排序不区分假名,在排序时将片假名和平假名字符视为相等。For Japanese collations, the _ks suffix indicates that a collation is kana-sensitive; that is, it distinguishes Katakana characters from Hiragana characters. Japanese collations without the _ks suffix 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 the binary collation of the binary character set, comparisons are based on numeric byte values. For the _bin collation 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 the binary collation of the binary character set and the _bin collations 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:

  • 对于 Unicode 字符集,xxx_general_mysql500_ci 排序规则保留了原始 xxx_general_ci 排序规则在 5.1.24 之前的顺序,并允许升级在 MySQL 5.1.24 之前创建的表(Bug #27877)。For Unicode character sets, the xxx_general_mysql500_ci collations preserve the pre-5.1.24 ordering of the original xxx_general_ci collations and permit upgrades for tables created before MySQL 5.1.24 (Bug #27877).