Mysql 简明教程
MySQL - Character Set
The MySQL Character Set
MySQL Character set 用于确定字符串中允许的一组字符。它允许以各种字符编码存储数据。默认情况下,MySQL 使用“utf8mb4”字符集。
The MySQL Character set is used to determine the set of permissible characters within a string. It allows for the storage of data in various character encodings. By default, MySQL uses the "utf8mb4" character set.
这些字符集提供多种功能 −
These character sets provides several functionalities −
-
*Storage Variety − *MySQL allows the storage of strings in various character sets.
-
*String Comparison − *Collations help in comparing strings based on the chosen character set.
-
*Mixed Character Sets − *It is possible to combine strings with different character sets or collations within the same server, database, or table.
-
*Specifying Character Set and Collation − *You can define the character set and collation at different levels of the database structure.
The MySQL Show Character-Set
您可以使用 MySQL SHOW CHARACTER SET 语句来查看所有可用字符集的列表。
You can use the MySQL SHOW CHARACTER SET statement to view the list of all the available character sets.
Syntax
以下为 SHOW CHARACTER SET 语句的语法 −
Following is the syntax of the SHOW CHARACTER SET statement −
SHOW CHARACTER SET [LIKE 'pattern' | WHERE expr]
The MySQL Set Character-set
MySQL SET CHARACTER SET 语句用于为字符集属性分配一个值。它使用指定映射集在服务器和当前客户端之间映射所有字符串。此语句更改“character_set_client”和“character_set_results”变量的值。
The MySQL SET CHARACTER SET Statement is used to assign a value to the character set attribute. It maps all the strings between the server and the current client with the specified mapping set. This statement changes values of the "character_set_client" and "character_set_results" variables.
Syntax
以下是 MySQL SET CHARACTER SET 语句的语法 -
Following is the syntax of the MySQL SET CHARACTER SET Statement −
SET {CHARACTER SET | CHARSET} {'charset_name' | DEFAULT}
其中,'charset_name' 是字符集的名称。
Where, 'charset_name' is the name of the character set.
Example
下面给出的查询设置字符集为“macroman” -
The query given below sets the character set to "macroman" −
SET CHARACTER SET macroman;
Verification
您可以使用 SHOW VARIABLES LIKE 语句来验证字符集的值,如下所示 -
You can verify the character set values using the SHOW VARIABLES LIKE statement as shown below −
SHOW VARIABLES LIKE "character_set_client";
以下是所获得的输出 −
Following is the output obtained −
现在验证“character_set_results”变量的当前值 -
Now verifying the current value of the "character_set_results" variable −
SHOW VARIABLES LIKE "character_set_results";
生成的结果如下所示 −
The result produced is as shown below −