SET NAMES
Syntax
SET NAMES {'charset_name' [COLLATE 'collation_name'] | DEFAULT}
Contents
Description
Sets the character_set_client, character_set_connection, character_set_results and, implicitly, the collation_connection session system variables to the specified character set and collation.
This determines which character set the client will use to send statements to the server, and the server will use for sending results back to the client.
ucs2
, utf16
, utf16le
and utf32
are not valid character sets for SET NAMES
, as they cannot be used as client character sets.
The collation clause is optional. If not defined (or if DEFAULT
is specified), the default collation for the character set will be used.
Quotes are optional for the character set or collation clauses.
Examples
Prior to MariaDB 10.6, the utf8 character set (and related collation) was the default for the given variables:
SELECT VARIABLE_NAME, SESSION_VALUE FROM INFORMATION_SCHEMA.SYSTEM_VARIABLES WHERE VARIABLE_NAME LIKE 'character_set_c%' OR VARIABLE_NAME LIKE 'character_set_re%' OR VARIABLE_NAME LIKE 'collation_c%'; +--------------------------+-----------------+ | VARIABLE_NAME | SESSION_VALUE | +--------------------------+-----------------+ | CHARACTER_SET_RESULTS | utf8 | | CHARACTER_SET_CONNECTION | utf8 | | CHARACTER_SET_CLIENT | utf8 | | COLLATION_CONNECTION | utf8_general_ci | +--------------------------+-----------------+ SET NAMES big5; SELECT VARIABLE_NAME, SESSION_VALUE FROM INFORMATION_SCHEMA.SYSTEM_VARIABLES WHERE VARIABLE_NAME LIKE 'character_set_c%' OR VARIABLE_NAME LIKE 'character_set_re%' OR VARIABLE_NAME LIKE 'collation_c%'; +--------------------------+-----------------+ | VARIABLE_NAME | SESSION_VALUE | +--------------------------+-----------------+ | CHARACTER_SET_RESULTS | big5 | | CHARACTER_SET_CONNECTION | big5 | | CHARACTER_SET_CLIENT | big5 | | COLLATION_CONNECTION | big5_chinese_ci | +--------------------------+-----------------+ SET NAMES 'latin1' COLLATE 'latin1_bin'; SELECT VARIABLE_NAME, SESSION_VALUE FROM INFORMATION_SCHEMA.SYSTEM_VARIABLES WHERE VARIABLE_NAME LIKE 'character_set_c%' OR VARIABLE_NAME LIKE 'character_set_re%' OR VARIABLE_NAME LIKE 'collation_c%'; +--------------------------+---------------+ | VARIABLE_NAME | SESSION_VALUE | +--------------------------+---------------+ | CHARACTER_SET_RESULTS | latin1 | | CHARACTER_SET_CONNECTION | latin1 | | CHARACTER_SET_CLIENT | latin1 | | COLLATION_CONNECTION | latin1_bin | +--------------------------+---------------+ SET NAMES DEFAULT; SELECT VARIABLE_NAME, SESSION_VALUE FROM INFORMATION_SCHEMA.SYSTEM_VARIABLES WHERE VARIABLE_NAME LIKE 'character_set_c%' OR VARIABLE_NAME LIKE 'character_set_re%' OR VARIABLE_NAME LIKE 'collation_c%'; +--------------------------+-------------------+ | VARIABLE_NAME | SESSION_VALUE | +--------------------------+-------------------+ | CHARACTER_SET_RESULTS | latin1 | | CHARACTER_SET_CONNECTION | latin1 | | CHARACTER_SET_CLIENT | latin1 | | COLLATION_CONNECTION | latin1_swedish_ci | +--------------------------+-------------------+
From MariaDB 10.6 to MariaDB 11.1, the utf8 character set (and related collations) became an alias for utf8mb3 rather than the other way around:
SELECT VARIABLE_NAME, SESSION_VALUE FROM INFORMATION_SCHEMA.SYSTEM_VARIABLES WHERE VARIABLE_NAME LIKE 'character_set_c%' OR VARIABLE_NAME LIKE 'character_set_re%' OR VARIABLE_NAME LIKE 'collation_c%'; +--------------------------+--------------------+ | VARIABLE_NAME | SESSION_VALUE | +--------------------------+--------------------+ | CHARACTER_SET_RESULTS | utf8mb3 | | CHARACTER_SET_CONNECTION | utf8mb3 | | CHARACTER_SET_CLIENT | utf8mb3 | | COLLATION_CONNECTION | utf8mb3_general_ci | +--------------------------+--------------------+ SET NAMES utf8mb4; SELECT VARIABLE_NAME, SESSION_VALUE FROM INFORMATION_SCHEMA.SYSTEM_VARIABLES WHERE VARIABLE_NAME LIKE 'character_set_c%' OR VARIABLE_NAME LIKE 'character_set_re%' OR VARIABLE_NAME LIKE 'collation_c%'; +--------------------------+--------------------+ | VARIABLE_NAME | SESSION_VALUE | +--------------------------+--------------------+ | CHARACTER_SET_RESULTS | utf8mb4 | | CHARACTER_SET_CONNECTION | utf8mb4 | | CHARACTER_SET_CLIENT | utf8mb4 | | COLLATION_CONNECTION | utf8mb4_general_ci | +--------------------------+--------------------+
From MariaDB 11.8, utf8mb4
became the default for the affected variables:
SET NAMES DEFAULT; SELECT VARIABLE_NAME, SESSION_VALUE FROM INFORMATION_SCHEMA.SYSTEM_VARIABLES WHERE VARIABLE_NAME LIKE 'character_set_con%' OR VARIABLE_NAME LIKE 'character_set_cl%' OR VARIABLE_NAME LIKE 'character_set_re%' OR VARIABLE_NAME LIKE 'collation_c%'; +--------------------------+-----------------------+ | VARIABLE_NAME | SESSION_VALUE | +--------------------------+-----------------------+ | CHARACTER_SET_RESULTS | utf8mb4 | | CHARACTER_SET_CONNECTION | utf8mb4 | | CHARACTER_SET_CLIENT | utf8mb4 | | COLLATION_CONNECTION | utf8mb4_uca1400_ai_ci | +--------------------------+-----------------------+