What is innodb_flush_log_at_trx_commit in MySQL

This article explains the role of the innodb_flush_log_at_trx_commit configuration parameter in MySQL, detailing how it balances ACID compliance and database performance. We will explore its three settings (0, 1, and 2), their impact on data durability, and how to choose the right value for your application’s specific needs.

Understanding the Parameter

The innodb_flush_log_at_trx_commit parameter controls how strictly MySQL adheres to the Durability (the “D” in ACID) of transactions. Specifically, it dictates when transaction log buffer contents are written to the redo log file and when those files are flushed (synced) to physical disk storage.

This setting represents a direct trade-off between write performance and data safety.

The Three Configuration Values

You can configure this parameter to one of three values: 0, 1, or 2.

Value 1 (Default: Full ACID Compliance)

Value 0 (Maximum Performance)

Value 2 (Balanced Compromise)

Comparison Summary

Value Write to OS Cache Flush to Physical Disk Data Loss Risk (MySQL Crash) Data Loss Risk (OS/Power Crash)
0 Once per second Once per second Up to 1 second Up to 1 second
1 Every commit Every commit None None
2 Every commit Once per second None Up to 1 second

How to Choose the Right Setting

The optimal setting depends on your application’s tolerance for data loss versus its performance requirements: