Skip to content

Latest commit

 

History

History
137 lines (100 loc) · 4.94 KB

sql-statement-set-names.md

File metadata and controls

137 lines (100 loc) · 4.94 KB
title summary aliases
SET [NAMES|CHARACTER SET]
TiDB 数据库中 SET [NAMES|CHARACTER SET] 的使用概况。
/docs-cn/dev/sql-statements/sql-statement-set-names/
/docs-cn/dev/reference/sql/statements/set-names/

SET [NAMES|CHARACTER SET]

SET NAMESSET CHARACTER SETSET CHARSET 语句用于修改当前连接的变量 character_set_clientcharacter_set_resultscharacter_set_connection

语法图

SetNamesStmt:

SetNamesStmt

VariableAssignmentList:

VariableAssignmentList

VariableAssignment:

VariableAssignment

CharsetName:

CharsetName

StringName:

StringName

CharsetKw:

CharsetKw

CharsetNameOrDefault:

CharsetNameOrDefault

示例

{{< copyable "sql" >}}

SHOW VARIABLES LIKE 'character_set%';
+--------------------------+--------------------------------------------------------+
| Variable_name            | Value                                                  |
+--------------------------+--------------------------------------------------------+
| character_sets_dir       | /usr/local/mysql-5.6.25-osx10.8-x86_64/share/charsets/ |
| character_set_connection | utf8mb4                                                |
| character_set_system     | utf8                                                   |
| character_set_results    | utf8mb4                                                |
| character_set_client     | utf8mb4                                                |
| character_set_database   | utf8mb4                                                |
| character_set_filesystem | binary                                                 |
| character_set_server     | utf8mb4                                                |
+--------------------------+--------------------------------------------------------+
8 rows in set (0.01 sec)

{{< copyable "sql" >}}

SET NAMES utf8;
Query OK, 0 rows affected (0.00 sec)

{{< copyable "sql" >}}

SHOW VARIABLES LIKE 'character_set%';
+--------------------------+--------------------------------------------------------+
| Variable_name            | Value                                                  |
+--------------------------+--------------------------------------------------------+
| character_sets_dir       | /usr/local/mysql-5.6.25-osx10.8-x86_64/share/charsets/ |
| character_set_connection | utf8                                                   |
| character_set_system     | utf8                                                   |
| character_set_results    | utf8                                                   |
| character_set_client     | utf8                                                   |
| character_set_server     | utf8mb4                                                |
| character_set_database   | utf8mb4                                                |
| character_set_filesystem | binary                                                 |
+--------------------------+--------------------------------------------------------+
8 rows in set (0.00 sec)

{{< copyable "sql" >}}

SET CHARACTER SET utf8mb4;
Query OK, 0 rows affected (0.00 sec)

{{< copyable "sql" >}}

SHOW VARIABLES LIKE 'character_set%';
+--------------------------+--------------------------------------------------------+
| Variable_name            | Value                                                  |
+--------------------------+--------------------------------------------------------+
| character_set_connection | utf8mb4                                                |
| character_set_system     | utf8                                                   |
| character_set_results    | utf8mb4                                                |
| character_set_client     | utf8mb4                                                |
| character_sets_dir       | /usr/local/mysql-5.6.25-osx10.8-x86_64/share/charsets/ |
| character_set_database   | utf8mb4                                                |
| character_set_filesystem | binary                                                 |
| character_set_server     | utf8mb4                                                |
+--------------------------+--------------------------------------------------------+
8 rows in set (0.00 sec)

MySQL 兼容性

SET [NAMES|CHARACTER SET] 语句与 MySQL 完全兼容。如发现任何兼容性差异,请在 GitHub 上提交 issue

另请参阅