character_set_server
Character set applied to new objects that do not name one.
- Padrão
utf8mb4- Range
- Any character set name installed on the server
- Restart needed
- Não
- Default checked on
- MySQL 8.4 LTS
O que faz
It is the server default for CREATE TABLE and CREATE DATABASE statements that omit a CHARACTER SET clause. Setting it changes nothing already stored: every column keeps the set it was created with. The client side sets (character_set_client, character_set_connection) are separate variables and unaffected.
Valor padrão
utf8mb4. utf8mb4 since MySQL 8.0 (latin1 in 5.7), same in MySQL 8.4.
Check the current value
SHOW GLOBAL VARIABLES LIKE 'character_set_server'; SELECT VARIABLE_NAME, VARIABLE_SOURCE, MIN_VALUE, MAX_VALUE, SET_TIME FROM performance_schema.variables_info WHERE VARIABLE_NAME = 'character_set_server';
Change it
SET SESSION character_set_server = 'utf8mb4'; -- this connection SET GLOBAL character_set_server = 'utf8mb4'; -- new connections, until restart SET PERSIST character_set_server = 'utf8mb4'; -- new connections, and after restarts
No restart. SET GLOBAL (or SET PERSIST, which also survives restarts) applies to connections opened afterwards; existing connections keep their session value unless they SET it themselves.
When to change it
Rarely on 8.0 or 8.4, where utf8mb4 is already what you want; keep latin1 as the default only so a legacy schema keeps creating latin1 columns without explicit clauses.
What can go wrong
If you change it, set collation_server too, or new objects get the character set's own default collation instead of the one you intended. Old columns keep their original set, so a schema can end up mixed utf8mb4 and latin1, and comparisons across the two go through conversion rules.
Questions about character_set_server
What is the default value of character_set_server in MySQL?
utf8mb4. utf8mb4 since MySQL 8.0 (latin1 in 5.7), same in MySQL 8.4.
Does changing character_set_server require a restart?
No. No restart. SET GLOBAL (or SET PERSIST, which also survives restarts) applies to connections opened afterwards; existing connections keep their session value unless they SET it themselves.
When should I change character_set_server?
Rarely on 8.0 or 8.4, where utf8mb4 is already what you want; keep latin1 as the default only so a legacy schema keeps creating latin1 columns without explicit clauses.
Back to all MySQL settings, or check the MySQL manual for every option.
Check character_set_server on your own server
SQLly runs the query above against MySQL and the other engines in this reference, from one desktop app on macOS, Windows and Linux.
Texto e dados desta página: CC BY 4.0, com crédito ao SQLly (sqlly.app). Código e trechos SQL: MIT. Detalhes da licença