MySql 中文参考指南

Chapter 12 Character Sets, Collations, Unicode

目录

Table of Contents

MySQL 包含字符集支持,它使您可以使用各种字符集存储数据,并根据各种校对规则执行比较。MySQL 服务器的默认字符集和校对规则为 utf8mb4utf8mb4_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.

UTF8utf8mb3 的已弃用别名,你应该期望它在未来的 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:

  1. What are character sets and collations?

  2. The multiple-level default system for character set assignment.

  3. Syntax for specifying character sets and collations.

  4. Affected functions and operations.

  5. Unicode support.

  6. The character sets and collations that are available, with notes.

  7. Selecting the language for error messages.

  8. 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';

有关为应用程序使用配置字符集以及客户端/服务器通信中的字符集相关问题的更多信息,请参阅 Section 12.5, “Configuring Application Character Set and Collation”Section 12.4, “Connection Character Sets and Collations”

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