官方文档地址:10.3 Specifying Character Sets and Collations
10.3.1 Collation Naming Conventions
10.3.2 Server Character Set and Collation
10.3.3 Database Character Set and Collation
10.3.4 Table Character Set and Collation
10.3.5 列字符集和排序规则
10.3.6 Character String Literal Character Set and Collation
10.3.7 预定义字符集
10.3.8 Character Set Introducers
10.3.9 Examples of Character Set and Collation Assignment
10.3.10 Compatibility with Other DBMSs
字符集和排序规则有四个级别的默认设置:服务器,数据库,表,列。下面几节中的描述可能看起来很复杂,但在实践中已经发现,多级默认设置会导致自然和明显的结果。
CHARACTER SET
子句用于指定字符集。CHARSET
可以用作CHARACTER SET
的同义词。
字符集问题不仅影响数据存储,还影响客户端程序与 MySQL 服务器之间的通信。如果您希望客户端程序使用不同于默认字符集的字符集与服务器通信,则需要指明是哪一个字符集。例如,要使用utf8mb4
Unicode 字符集,请在连接到服务器后发出以下语句:
SET NAMES 'utf8mb4';
有关客户端/服务器通信中字符集相关问题的更多信息,请参见 10.4 连接的字符集和排序规则。