Purpose
This statement is used to set the character set and collation for the current session.
Syntax
SET NAMES 'charset_name' [COLLATE 'collation_name']
Parameters
| Parameter | Description |
|---|---|
| charset_name | Specifies the character set. |
| collation_name | Specifies the collation for the character set. If not specified, the default collation for the character set is used. |
Note
You can use SHOW CHARSET; to query the supported character sets and SHOW COLLATION; to query the supported collations.
Examples
Set the character set for the current session to
gbkwith the default collation.obclient> SET NAMES 'gbk'; obclient> SHOW VARIABLES LIKE 'character_set_c%'; obclient> SHOW VARIABLES LIKE 'collation_connection';Set the character set for the current session to
utf8mb4with theutf8mb4_general_cicollation.obclient> SET NAMES 'utf8mb4' COLLATE 'utf8mb4_general_ci'; obclient> SHOW VARIABLES LIKE 'character_set_c%'; obclient> SHOW VARIABLES LIKE 'collation_connection';
