Purpose
This statement sets the character set and collation for the current session.
Syntax
SET NAMES 'charset_name' [COLLATE 'collation_name']
Parameters
| Parameter | Description |
|---|---|
| charset_name | The specified character set. |
| collation_name | The specified collation for the character set. If this parameter is not specified, the default collation of the character set is used. |
Note
You can execute the SHOW CHARSET; statement to query the character sets supported by the system, and execute the SHOW COLLATION; statement to query the collations supported by the system.
Examples
Set the character set of the current session to
gbkand the collation to the default collation of the character set.obclient> SET NAMES 'gbk'; obclient> SHOW VARIABLES LIKE 'character_set_c%'; obclient> SHOW VARIABLES LIKE 'collation_connection';Set the character set of the current session to
utf8mb4and the collation toutf8mb4_general_ci.obclient> SET NAMES 'utf8mb4' COLLATE 'utf8mb4_general_ci'; obclient> SHOW VARIABLES LIKE 'character_set_c%'; obclient> SHOW VARIABLES LIKE 'collation_connection';