8.4 中文镜像

MySQL 8.4 参考手册 · 中文镜像

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

打开官方英文原文 ↗

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

MySQL 8.4 参考手册 / 12 种字符集、排序规则、Unicode
中文点击中文段落可显示 / 隐藏英文原文本页译文覆盖 100%

第 12 章 字符集、校对规则、UnicodeChapter 12 Character Sets, Collations, Unicode

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.

Note

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”.