innodb_flush_log_at_trx_commit
When InnoDB writes and flushes the redo log for a commit.
- 預設
1- Range
- 0, 1, 2
- Restart needed
- 否
- Default checked on
- MySQL 8.4 LTS
其作用
1 writes and flushes at every commit (full durability). 2 writes at commit and flushes about once a second: a mysqld crash loses nothing, an OS crash or power loss can lose about a second. 0 writes and flushes about once a second: even a mysqld crash can lose about a second.
預設值
1. 1 (MySQL 8.4).
Check the current value
SHOW GLOBAL VARIABLES LIKE 'innodb_flush_log_at_trx_commit'; SELECT VARIABLE_NAME, VARIABLE_SOURCE, MIN_VALUE, MAX_VALUE, SET_TIME FROM performance_schema.variables_info WHERE VARIABLE_NAME = 'innodb_flush_log_at_trx_commit';
Change it
SET GLOBAL innodb_flush_log_at_trx_commit = 2; -- until the next restart SET PERSIST innodb_flush_log_at_trx_commit = 2; -- now and after restarts
No restart. SET GLOBAL or SET PERSIST takes effect immediately; SET PERSIST also writes mysqld-auto.cnf so the value survives restarts.
When to change it
Use 2 on replicas you can rebuild or for bulk loads where a second of loss is acceptable; keep 1 on primaries holding data you cannot lose.
What can go wrong
0 or 2 can lose acknowledged transactions and leave the binary log ahead of InnoDB after a crash.
The closest setting on other engines
| 引擎 | 設定 | 預設 | Restart |
|---|---|---|---|
| MySQL |
innodb_flush_log_at_trx_commit this page
|
1 |
否 |
| PostgreSQL |
synchronous_commit
|
on |
否 |
| SQL Server |
DELAYED_DURABILITY
|
DISABLED |
否 |
| SQLite |
synchronous
|
2 (FULL) |
否 |
Questions about innodb_flush_log_at_trx_commit
What is the default value of innodb_flush_log_at_trx_commit in MySQL?
1. 1 (MySQL 8.4).
Does changing innodb_flush_log_at_trx_commit require a restart?
No. No restart. SET GLOBAL or SET PERSIST takes effect immediately; SET PERSIST also writes mysqld-auto.cnf so the value survives restarts.
When should I change innodb_flush_log_at_trx_commit?
Use 2 on replicas you can rebuild or for bulk loads where a second of loss is acceptable; keep 1 on primaries holding data you cannot lose.
Back to all MySQL settings, or check the MySQL manual for every option.
Check innodb_flush_log_at_trx_commit 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.