Table of Contents
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. MySQL包括字符集支持,使您能够使用各种字符集存储数据,并根据各种排序规则进行比较。The default MySQL server character set and collation are 默认的MySQL服务器字符集和排序规则是utf8mb4
and utf8mb4_0900_ai_ci
, but you can specify character sets at the server, database, table, column, and string literal levels.utf8mb4
和utf8mb4_0900_ai_ci
,但您可以在服务器、数据库、表、列和字符串文字级别指定字符集。
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 support.Unicode支持。
The character sets and collations that are available, with notes.可用的字符集和排序规则,以及注释。
Selecting the language for error messages.选择错误消息的语言。
Selecting the locale for day and month names.选择日期和月份名称的区域设置。
Character set issues affect not only data storage, but also communication between client programs and the MySQL server. 字符集问题不仅会影响数据存储,还会影响客户端程序和MySQL服务器之间的通信。If you want the client program to communicate with the server using a character set different from the default, you'll need to indicate which one. 如果您希望客户端程序使用不同于默认值的字符集与服务器通信,则需要指明是哪一个字符集。For example, to use the 例如,要使用utf8
Unicode character set, issue this statement after connecting to the server:utf8
Unicode字符集,请在连接到服务器后发出以下语句:
SET NAMES 'utf8';
For more information about configuring character sets for application use and character set-related issues in client/server communication, see Section 10.5, “Configuring Application Character Set and Collation”, and Section 10.4, “Connection Character Sets and Collations”.有关为应用程序使用配置字符集以及客户端/服务器通信中与字符集相关的问题的更多信息,请参阅第10.5节,“配置应用程序字符集和排序规则”和第10.4节,“连接字符集和排列规则”。