sql_mode
SQL syntax and validation rules, as a comma-separated list of modes.
- デフォルト
ONLY_FULL_GROUP_BY, STRICT_TRANS_TABLES, NO_ZERO_IN_DATE, NO_ZERO_DATE, ERROR_FOR_DIVISION_BY_ZERO, NO_ENGINE_SUBSTITUTION- Range
- Comma-separated mode names, or ''
- Restart needed
- いいえ
- Default checked on
- MySQL 8.4 LTS
何ができるか
Controls strictness: STRICT_TRANS_TABLES rejects invalid or truncated data instead of warning, ONLY_FULL_GROUP_BY rejects non-aggregated columns not in GROUP BY.
デフォルト値
ONLY_FULL_GROUP_BY, STRICT_TRANS_TABLES, NO_ZERO_IN_DATE, NO_ZERO_DATE, ERROR_FOR_DIVISION_BY_ZERO, NO_ENGINE_SUBSTITUTION. That list is the default since MySQL 8.0; same in 8.4.
Check the current value
SHOW GLOBAL VARIABLES LIKE 'sql_mode'; SELECT VARIABLE_NAME, VARIABLE_SOURCE, MIN_VALUE, MAX_VALUE, SET_TIME FROM performance_schema.variables_info WHERE VARIABLE_NAME = 'sql_mode';
Change it
SET SESSION sql_mode = 'STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION'; -- this connection SET GLOBAL sql_mode = 'STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION'; -- new connections, until restart SET PERSIST sql_mode = 'STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION'; -- 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
Only to keep a legacy application working while you fix its queries; set it per session for that application rather than globally.
What can go wrong
Removing strict modes lets bad data in silently (truncated strings, zero dates); removing ONLY_FULL_GROUP_BY allows queries with arbitrary results.
Questions about sql_mode
What is the default value of sql_mode in MySQL?
ONLY_FULL_GROUP_BY, STRICT_TRANS_TABLES, NO_ZERO_IN_DATE, NO_ZERO_DATE, ERROR_FOR_DIVISION_BY_ZERO, NO_ENGINE_SUBSTITUTION. That list is the default since MySQL 8.0; same in 8.4.
Does changing sql_mode 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 sql_mode?
Only to keep a legacy application working while you fix its queries; set it per session for that application rather than globally.
Back to all MySQL settings, or check the MySQL manual for every option.
Check sql_mode 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.