All Products
Search
Document Center

SET NAMES

Last Updated: Jun 18, 2021

Description

This statement sets the character set encoding for the current connected database.

Syntax

SET NAMES 'charset_name' [COLLATE 'collation_name']

Parameter description

Parameter

Description

charset_name

Specifies a character set.

collation_name

Specifies a collation for the character set. If you do not specify this parameter, the default collation for the character set is used.

Note

This statement specifies three session system variables character_set_client, character_set_connection, and character_set_results as the specified character set. This statement specifies character_set_connection as charset_name, and collation_connection as the default collation of charset_name.

Examples

  • Specify the character set and collation of the database.

OceanBase(admin@test)>SET NAMES 'utf8mb4' COLLATE 'utf8mb4_general_ci';
Query OK, 0 rows affected (0.00 sec)

OceanBase(admin@test)>show variables like 'character_set_c%';
+--------------------------+---------+
| Variable_name            | Value   |
+--------------------------+---------+
| character_set_client     | utf8mb4 |
| character_set_connection | utf8mb4 |
+--------------------------+---------+
2 rows in set (0.01 sec)

OceanBase(admin@test)>show variables like 'collation_connection';
+----------------------+--------------------+
| Variable_name        | Value              |
+----------------------+--------------------+
| collation_connection | utf8mb4_general_ci |
+----------------------+--------------------+
1 row in set (0.05 sec)


OceanBase(admin@test)>SET NAMES 'gbk';
Query OK, 0 rows affected (0.02 sec)

OceanBase(admin@test)>show variables like 'character_set_c%';
+--------------------------+-------+
| Variable_name            | Value |
+--------------------------+-------+
| character_set_client     | gbk   |
| character_set_connection | gbk   |
+--------------------------+-------+
2 rows in set (0.01 sec)


OceanBase(admin@test)>show variables like 'collation_connection';
+----------------------+----------------+
| Variable_name        | Value          |
+----------------------+----------------+
| collation_connection | gbk_chinese_ci |
+----------------------+----------------+
1 row in set (0.01 sec)