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

MySQL 8.4 参考手册 · 中文镜像

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

打开官方英文原文 ↗

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

MySQL 8.4 参考手册 / 12 种字符集、排序规则、Unicode / 12.9 统一码支持 / 12.9.2 utf8mb3 字符集(3 字节 UTF-8 Unicode 编码)
中文点击中文段落可显示 / 隐藏英文原文本页译文覆盖 100%

12.9.2 utf8mb3 字符集(3 字节 UTF-8 Unicode 编码)12.9.2 The utf8mb3 Character Set (3-Byte UTF-8 Unicode Encoding)

utf8mb3 字符集具有以下特性:The utf8mb3 character set has these characteristics:

  • 仅支持 BMP 字符(不支持补充字符)Supports BMP characters only (no support for supplementary characters)

  • 每个多字节字符最多需要三个字节。Requires a maximum of three bytes per multibyte character.

使用 UTF-8 数据但需要补充字符支持的应用程序应使用 utf8mb4 而不是 utf8mb3(参见 第 12.9.1 节,“utf8mb4 字符集(4 字节 UTF-8 Unicode 编码)”)。Applications that use UTF-8 data but require supplementary character support should use utf8mb4 rather than utf8mb3 (see Section 12.9.1, “The utf8mb4 Character Set (4-Byte UTF-8 Unicode Encoding)”).

utf8mb3 和 ucs2 中可用的字符集完全相同。也就是说,它们具有相同的 字符集(repertoire)。Exactly the same set of characters is available in utf8mb3 and ucs2. That is, they have the same repertoire.

Note

MySQL 推荐的字符集是 utf8mb4。所有新应用程序都应使用 utf8mb4。The recommended character set for MySQL is utf8mb4. All new applications should use utf8mb4.

utf8mb3 字符集已被弃用。utf8mb3 在 MySQL 8.0.x 和 MySQL 8.4.x LTS 版本系列的生命周期内仍然受支持。The utf8mb3 character set is deprecated. utf8mb3 remains supported for the lifetimes of the MySQL 8.0.x and MySQL 8.4.x LTS release series.

预计 utf8mb3 将在 MySQL 的未来主要版本中被移除。Expect utf8mb3 to be removed in a future major release of MySQL.

由于更改字符集可能是一个复杂且耗时的任务,你应该现在就开始准备这一更改,通过在新应用程序中使用 utf8mb4。有关将现有使用 utf8mb3 的应用程序进行转换的指导,请参阅 第 12.9.8 节,“3 字节与 4 字节 Unicode 字符集之间的转换”。Since changing character sets can be a complex and time-consuming task, you should begin to prepare for this change now by using utf8mb4 for new applications. For guidance in converting existing applications which use utfmb3, see Section 12.9.8, “Converting Between 3-Byte and 4-Byte Unicode Character Sets”.

utf8mb3 可以用于 CHARACTER SET 子句,而 utf8mb3_collation_substring 可以用于 COLLATE 子句,其中 collation_substring 可以是 bin、czech_ci、danish_ci、esperanto_ci、estonian_ci 等等。例如:utf8mb3 can be used in CHARACTER SET clauses, and utf8mb3_collation_substring in COLLATE clauses, where collation_substring is bin, czech_ci, danish_ci, esperanto_ci, estonian_ci, and so forth. For example:

CREATE TABLE t (s1 CHAR(1)) CHARACTER SET utf8mb3;
SELECT * FROM t WHERE s1 COLLATE utf8mb3_general_ci = 'x';
DECLARE x VARCHAR(5) CHARACTER SET utf8mb3 COLLATE utf8mb3_danish_ci;
SELECT CAST('a' AS CHAR CHARACTER SET utf8mb4) COLLATE utf8mb4_czech_ci;

在诸如 SHOW CREATE TABLE 或 SELECT CHARACTER_SET_NAME FROM INFORMATION_SCHEMA.COLUMNS 或 SELECT COLLATION_NAME FROM INFORMATION_SCHEMA.COLUMNS 这样的语句中,以 utf8 或 utf8_ 为前缀的字符集或排序规则名称会分别显示为 utf8mb3 或 utf8mb3_。In statements such as SHOW CREATE TABLE or SELECT CHARACTER_SET_NAME FROM INFORMATION_SCHEMA.COLUMNS or SELECT COLLATION_NAME FROM INFORMATION_SCHEMA.COLUMNS, character sets or collation names prefixed with utf8 or utf8_ are displayed using utf8mb3 or utf8mb3_, respectively.

utf8mb3 在 CHARACTER SET 子句之外的上下文中也是有效的(但已弃用)。例如:utf8mb3 is also valid (but deprecated) in contexts other than CHARACTER SET clauses. For example:

mysqld --character-set-server=utf8mb3
SET NAMES 'utf8mb3'; /* and other SET statements that have similar effect */
SELECT _utf8mb3 'a';

有关多字节字符集相关的数据类型存储信息,请参见 字符串类型存储要求。For information about data type storage as it relates to multibyte character sets, see String Type Storage Requirements.