// mysql · sql behavior

collation_server

Collation applied to new objects that do not name one.

По умолчанию
utf8mb4_0900_ai_ci
Range
Any collation whose character set matches character_set_server
Restart needed
Нет
Default checked on
MySQL 8.4 LTS

Что оно делает

It pairs with character_set_server and only reaches objects created after the change, so existing columns compare and sort exactly as before. The default utf8mb4_0900_ai_ci is accent insensitive and case insensitive; picking _as_cs or _bin makes new columns compare strictly.

Значение по умолчанию

utf8mb4_0900_ai_ci. utf8mb4_0900_ai_ci (MySQL 8.4); assigning a user-defined collation raises a warning instead of an error.

Check the current value

SHOW GLOBAL VARIABLES LIKE 'collation_server';

SELECT VARIABLE_NAME, VARIABLE_SOURCE, MIN_VALUE, MAX_VALUE, SET_TIME
FROM performance_schema.variables_info
WHERE VARIABLE_NAME = 'collation_server';

Change it

SET SESSION collation_server = 'utf8mb4_0900_as_cs';   -- this connection
SET GLOBAL collation_server = 'utf8mb4_0900_as_cs';    -- new connections, until restart
SET PERSIST collation_server = 'utf8mb4_0900_as_cs';   -- 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

When new schemas should default to case or accent sensitive comparisons without spelling the collation in every CREATE statement.

What can go wrong

Changing the variable leaves stored columns untouched, and one schema can easily hold columns with three different collations, so check SHOW CREATE TABLE or information_schema.COLUMNS for what a query actually compares with rather than the server variable.

Questions about collation_server

What is the default value of collation_server in MySQL?

utf8mb4_0900_ai_ci. utf8mb4_0900_ai_ci (MySQL 8.4); assigning a user-defined collation raises a warning instead of an error.

Does changing collation_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 collation_server?

When new schemas should default to case or accent sensitive comparisons without spelling the collation in every CREATE statement.

Back to all MySQL settings, or check the MySQL manual for every option.

// one client for every engine

Check collation_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.

Текст и данные на этой странице: CC BY 4.0, с указанием SQLly (sqlly.app). Код и фрагменты SQL: MIT. Подробнее о лицензии