lock_wait_timeout
Seconds to wait for a metadata lock (DDL, LOCK TABLES, FLUSH TABLES).
- デフォルト
31536000 (1 year)- Range
- 1 to 31536000 seconds
- Restart needed
- いいえ
- Default checked on
- MySQL 8.4 LTS
何ができるか
An ALTER TABLE waiting for a metadata lock blocks new queries on that table behind it, so a long wait is effectively an outage.
デフォルト値
31536000 (1 year). 31536000 seconds (MySQL 8.4).
Check the current value
SHOW GLOBAL VARIABLES LIKE 'lock_wait_timeout'; SELECT VARIABLE_NAME, VARIABLE_SOURCE, MIN_VALUE, MAX_VALUE, SET_TIME FROM performance_schema.variables_info WHERE VARIABLE_NAME = 'lock_wait_timeout';
Change it
SET SESSION lock_wait_timeout = 10; -- this connection SET GLOBAL lock_wait_timeout = 10; -- new connections, until restart SET PERSIST lock_wait_timeout = 10; -- 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
Set it low in the session that runs migrations so DDL fails fast instead of queueing behind a long transaction.
What can go wrong
DDL fails and must be retried.
Questions about lock_wait_timeout
What is the default value of lock_wait_timeout in MySQL?
31536000 (1 year). 31536000 seconds (MySQL 8.4).
Does changing lock_wait_timeout 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 lock_wait_timeout?
Set it low in the session that runs migrations so DDL fails fast instead of queueing behind a long transaction.
Back to all MySQL settings, or check the MySQL manual for every option.
Related on SQLly
Check lock_wait_timeout 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.