max_execution_time
Milliseconds after which a read-only SELECT is aborted; 0 disables.
- 默认
0 (disabled)- Range
- 0 to 2^64-1 ms
- Restart needed
- 否
- Default checked on
- MySQL 8.4 LTS
作用
Applies only to read-only SELECT statements, not to INSERT ... SELECT or other DML. A per-query hint, SELECT /*+ MAX_EXECUTION_TIME(1000) */ ..., overrides it.
默认值
0 (disabled). 0 (MySQL 8.4).
Check the current value
SHOW GLOBAL VARIABLES LIKE 'max_execution_time'; SELECT VARIABLE_NAME, VARIABLE_SOURCE, MIN_VALUE, MAX_VALUE, SET_TIME FROM performance_schema.variables_info WHERE VARIABLE_NAME = 'max_execution_time';
Change it
SET SESSION max_execution_time = 30000; -- this connection SET GLOBAL max_execution_time = 30000; -- new connections, until restart SET PERSIST max_execution_time = 30000; -- 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
For reporting users or ad hoc query tools, so an accidental cross join does not run for hours.
What can go wrong
Statements fail with error 3024 (maximum statement execution time exceeded).
The closest setting on other engines
| 引擎 | 设置项 | 默认 | Restart |
|---|---|---|---|
| MySQL |
max_execution_time this page
|
0 (disabled) |
否 |
| PostgreSQL |
statement_timeout
|
0 (disabled) |
否 |
Questions about max_execution_time
What is the default value of max_execution_time in MySQL?
0 (disabled). 0 (MySQL 8.4).
Does changing max_execution_time 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 max_execution_time?
For reporting users or ad hoc query tools, so an accidental cross join does not run for hours.
Back to all MySQL settings, or check the MySQL manual for every option.
Related on SQLly
Check max_execution_time 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.