Binlog's brushing strategy

mysql will only record the binlog log when the transaction is committed. At this time, the log is still in memory. When is the binlog flushed to the disk?
mysql controls flushing through sync_binlog, the value range is 0~n
0: flushing is not mandatory, and the system determines when to write binlog to disk;
1: Binlog is written to disk every time a transaction is submitted;
n: every time a transaction is submitted n transactions write binlog to disk;

  • Obviously, a sync_binlog of 1 is the safest. Binlog is written to disk every time a transaction is committed, and the data consistency is the best. However, in actual situations, in order to improve the performance of the database, sync_binlog is appropriately set to reduce the number of disk IOs, and data consistency is exchanged for performance.
  • In business scenarios where database consistency is not high or data is not that important, sync_binlog can be set to a value in the range of 100 to 1000 to improve database performance. In business scenarios that require high data consistency or particularly important data, such as orders, it is recommended to set the value of sync_binlog to 1, so as to ensure that data will not be lost even if the database is hung up.
  • The default value of sync_binlog is 0. At this time, the system will determine when to write binlog to disk. The database may consider the size of the cached binlog log when it is idle to decide whether to write the binlog to the disk.

Guess you like

Origin blog.csdn.net/feifeixiongxiong/article/details/113132424