innodb_autoinc_lock_mode
Locking used to generate AUTO_INCREMENT values.
- Predeterminado
2- Range
- 0, 1, 2
- Restart needed
- Sí
- Default checked on
- MySQL 8.4 LTS
Lo que hace
2 (interleaved) needs no table-level lock and is fastest, but values from concurrent multi-row inserts can interleave, so INSERT ... SELECT does not get consecutive values. It is safe with row-based binary logging.
Valor predeterminado
2. 2 since MySQL 8.0 (1 in 5.7). Same in 8.4.
Check the current value
SHOW GLOBAL VARIABLES LIKE 'innodb_autoinc_lock_mode'; SELECT VARIABLE_NAME, VARIABLE_SOURCE, MIN_VALUE, MAX_VALUE, SET_TIME FROM performance_schema.variables_info WHERE VARIABLE_NAME = 'innodb_autoinc_lock_mode';
Change it
SET PERSIST_ONLY innodb_autoinc_lock_mode = 1; -- then restart mysqld (or set it under [mysqld] in my.cnf)
Restart required: the variable is read-only at runtime (SET GLOBAL fails with error 1238). Stage it with SET PERSIST_ONLY or under [mysqld] in my.cnf.
When to change it
Set 1 only if you still replicate with statement-based binary logging.
What can go wrong
With statement-based replication, mode 2 can produce different values on replicas.
Questions about innodb_autoinc_lock_mode
What is the default value of innodb_autoinc_lock_mode in MySQL?
2. 2 since MySQL 8.0 (1 in 5.7). Same in 8.4.
Does changing innodb_autoinc_lock_mode require a restart?
Yes. Restart required: the variable is read-only at runtime (SET GLOBAL fails with error 1238). Stage it with SET PERSIST_ONLY or under [mysqld] in my.cnf.
When should I change innodb_autoinc_lock_mode?
Set 1 only if you still replicate with statement-based binary logging.
Back to all MySQL settings, or check the MySQL manual for every option.
Check innodb_autoinc_lock_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.