- 12.1 字符集和整理规则概述12.1 Character Sets and Collations in General
- 12.2 MySQL 中的字符集和整理规则12.2 Character Sets and Collations in MySQL
- 12.3 指定字符集和整理规则12.3 Specifying Character Sets and Collations
- 12.3.1 整理规则命名约定12.3.1 Collation Naming Conventions
- 12.3.2 服务器字符集和排序规则12.3.2 Server Character Set and Collation
- 12.3.3 数据库字符集和排序规则12.3.3 Database Character Set and Collation
- 12.3.4 表字符集和排序规则12.3.4 Table Character Set and Collation
- 12.3.5 列字符集和排序规则12.3.5 Column Character Set and Collation
- 12.3.6 字符串字面量字符集和排序规则12.3.6 Character String Literal Character Set and Collation
- 12.3.7 国家字符集12.3.7 The National Character Set
- 12.3.8 字符集引入器12.3.8 Character Set Introducers
- 12.3.9 字符集和排序规则分配示例12.3.9 Examples of Character Set and Collation Assignment
- 12.3.10 与其他数据库管理系统的兼容性12.3.10 Compatibility with Other DBMSs
- 12.4 连接字符集和排序规则12.4 Connection Character Sets and Collations
- 12.5 配置应用程序字符集和排序规则12.5 Configuring Application Character Set and Collation
- 12.6 错误消息字符集12.6 Error Message Character Set
- 12.7 列字符集转换12.7 Column Character Set Conversion
- 12.8 排序规则问题12.8 Collation Issues
- 12.8.1 在 SQL 语句中使用 COLLATE12.8.1 Using COLLATE in SQL Statements
- 12.8.2 COLLATE 子句优先级12.8.2 COLLATE Clause Precedence
- 12.8.3 字符集与排序规则兼容性12.8.3 Character Set and Collation Compatibility
- 12.8.4 表达式中的排序规则强制性12.8.4 Collation Coercibility in Expressions
- 12.8.5 二进制排序规则与_bin 排序规则的比较12.8.5 The binary Collation Compared to _bin Collations
- 12.8.6 排序规则效果的示例12.8.6 Examples of the Effect of Collation
- 12.8.7 在 INFORMATION_SCHEMA 搜索中使用排序规则12.8.7 Using Collation in INFORMATION_SCHEMA Searches
- 12.9 Unicode 支持12.9 Unicode Support
- 12.9.1 utf8mb4 字符集(4 字节 UTF-8 Unicode 编码)12.9.1 The utf8mb4 Character Set (4-Byte UTF-8 Unicode Encoding)
- 12.9.2 utf8mb3 字符集(3 字节 UTF-8 Unicode 编码)12.9.2 The utf8mb3 Character Set (3-Byte UTF-8 Unicode Encoding)
- 12.9.3 utf8 字符集(utf8mb3 的废弃别名)12.9.3 The utf8 Character Set (Deprecated alias for utf8mb3)
- 12.9.4 ucs2 字符集(UCS-2 Unicode 编码)12.9.4 The ucs2 Character Set (UCS-2 Unicode Encoding)
- 12.9.5 utf16 字符集(UTF-16 Unicode 编码)12.9.5 The utf16 Character Set (UTF-16 Unicode Encoding)
- 12.9.6 utf16le 字符集(UTF-16LE Unicode 编码)12.9.6 The utf16le Character Set (UTF-16LE Unicode Encoding)
- 12.9.7 utf32 字符集(UTF-32 Unicode 编码)12.9.7 The utf32 Character Set (UTF-32 Unicode Encoding)
- 12.9.8 在 3 字节和 4 字节 Unicode 字符集之间转换12.9.8 Converting Between 3-Byte and 4-Byte Unicode Character Sets
- 12.10 支持的字符集和排序规则12.10 Supported Character Sets and Collations
- 12.10.1 Unicode 字符集12.10.1 Unicode Character Sets
- 12.10.2 西欧字符集12.10.2 West European Character Sets
- 12.10.3 中欧字符集12.10.3 Central European Character Sets
- 12.10.4 南欧和中东字符集12.10.4 South European and Middle East Character Sets
- 12.10.5 波罗的海字符集12.10.5 Baltic Character Sets
- 12.10.6 西里尔字符集12.10.6 Cyrillic Character Sets
- 12.10.7 亚洲字符集12.10.7 Asian Character Sets
- 12.10.8 二进制字符集12.10.8 The Binary Character Set
- 12.11 字符集的限制12.11 Restrictions on Character Sets
- 12.12 设置错误信息语言12.12 Setting the Error Message Language
- 12.13 添加字符集12.13 Adding a Character Set
- 12.14 向字符集添加排序规则12.14 Adding a Collation to a Character Set
- 12.15 字符集配置12.15 Character Set Configuration
- 12.16 MySQL 服务器区域设置支持12.16 MySQL Server Locale Support
MySQL 包含字符集支持,使您能够使用各种字符集存储数据,并根据各种校对规则进行比较。默认的 MySQL 服务器字符集和校对规则是 utf8mb4 和 utf8mb4_0900_ai_ci,但您可以在服务器、数据库、表、列和字符串字面值级别指定字符集。为了最大限度地提高数据和应用程序的互操作性和未来兼容性,我们建议您尽可能使用 utf8mb4 字符集。MySQL includes character set support that enables you to store data
using a variety of character sets and perform comparisons according
to a variety of collations. The default MySQL server character set
and collation are utf8mb4 and
utf8mb4_0900_ai_ci, but you can specify character
sets at the server, database, table, column, and string literal
levels. To maximize interoperability and future-proofing of your
data and applications, we recommend that you use the
utf8mb4 character set whenever possible.
UTF8 是 utf8mb3 的已弃用同义词,您应该预期它将在未来的 MySQL 版本中被移除。请改为指定 utfmb3 或(更推荐) utfmb4。UTF8 is a deprecated synonym for
utf8mb3, and you should expect it to be removed
in a future version of MySQL. Specify utfmb3 or
(preferably) utfmb4 instead.
本章讨论以下主题:This chapter discusses the following topics:
什么是字符集和排序规则?What are character sets and collations?
字符集分配的多级默认系统。The multiple-level default system for character set assignment.
指定字符集和排序规则的语法。Syntax for specifying character sets and collations.
受影响的函数和操作。Affected functions and operations.
Unicode 支持。Unicode support.
可用的字符集和排序规则,并附备注。The character sets and collations that are available, with notes.
选择错误消息的语言。Selecting the language for error messages.
选择星期和月份名称的区域设置。Selecting the locale for day and month names.
字符集问题不仅影响数据存储,还会影响客户端程序与 MySQL 服务器之间的通信。如果希望客户端程序使用不同于默认的字符集与服务器进行通信,需要指明所使用的字符集。例如,要使用 latin1 Unicode 字符集,在连接服务器后执行以下语句:Character set issues affect not only data storage, but also
communication between client programs and the MySQL server. If you
want the client program to communicate with the server using a
character set different from the default, you need to indicate which
one. For example, to use the latin1 Unicode
character set, issue this statement after connecting to the server:
SET NAMES 'latin1';
有关为应用程序使用配置字符集以及客户端/服务器通信中的字符集相关问题的更多信息,请参阅 第 12.5 节,“配置应用程序字符集和排序规则”,以及 第 12.4 节,“连接字符集和排序规则”。For more information about configuring character sets for application use and character set-related issues in client/server communication, see Section 12.5, “Configuring Application Character Set and Collation”, and Section 12.4, “Connection Character Sets and Collations”.