How to distinguish MySQL's innodb_flush_log_at_trx_commit and sync_binlog

How to distinguish MySQL's innodb_flush_log_at_trx_commit and sync_binlog

The two parameters innodb_flush_log_at_trx_commit and sync_binlog are key parameters for controlling MySQL disk write strategy and data security.

show variables like "innodb_flush_log_at_trx_commit";

innodb_flush_log_at_trx_commit:

0: MySQL's main_thread writes the redo log in the storage engine log buffer to the log file every second, and calls the file system's sync operation to refresh the log to disk.

1: Each time a transaction is committed, the redo log in the storage engine log buffer is written to the log file, and the file system's sync operation is called to refresh the log to the disk.

2: Each time a transaction is committed, the redo log in the storage engine log buffer is written to the log file, and the storage engine's main_thread flushes the log to disk every second.

show variables like "sync_binlog";

sync_binlog:

0: The storage engine does not flush binlog to disk, and the operating system's file system controls cache flushing.

1: Each time a transaction is submitted, the storage engine calls the file system's sync operation to refresh the cache. This method is the safest, but has lower performance.

n: When the submitted log group = n, the storage engine calls the file system's sync operation to refresh the cache.

sync_binlog=0 or sync_binlog is greater than 1, the transaction is committed but not yet synchronized to disk. Therefore, in the event of a power failure or operating system crash it is possible that the server has committed some transactions that have not yet been synchronized to the binary log. Therefore it is not possible to perform routine recovery of these transactions, as they will be lost in the binary log.

It is safest when both innodb_flush_log_at_trx_commit and sync_binlog are 1. In the event of a mysqld service crash or a server host crash, the binary log may lose at most one statement or one transaction. However, you cannot have your cake and eat it too. Double 1, 1 will lead to frequent IO operations, so this mode is also the slowest way.

In actual use, it is necessary to consider the business needs for performance and security, and comprehensively consider the settings of the two parameters. The above picture shows the parameters of our online machine.

The above is the details of how to distinguish MySQL's innodb_flush_log_at_trx_commit and sync_binlog. For more information about MySQL's innodb_flush_log_at_trx_commit and sync_binlog, please pay attention to other related articles on 123WORDPRESS.COM!

You may also be interested in:
  • Summary of MySQL InnoDB architecture
  • A brief introduction to MySQL InnoDB ReplicaSet
  • Detailed explanation of memory management of MySQL InnoDB storage engine
  • MySQL Innodb key features insert buffer
  • Summary of MySQL InnoDB locks
  • Detailed Example of MySQL InnoDB Locking Mechanism
  • In-depth explanation of InnoDB locks in MySQL technology
  • Change the MySQL database engine to InnoDB
  • Briefly describe the MySQL InnoDB storage engine
  • MySQL InnoDB tablespace encryption example detailed explanation
  • MySQL InnoDB transaction lock source code analysis

<<:  Detailed Analysis of the Differences between break and last in Nginx

>>:  HTML hyperlinks explained in detail

Recommend

Optimization methods when Mysql occupies too high CPU (must read)

When Mysql occupies too much CPU, where should we...

A brief comparison of Props in React

Table of contents Props comparison of class compo...

Echart Bar double column chart style most complete detailed explanation

Table of contents Preface Installation and Config...

How to set password for mysql version 5.6 on mac

MySQL can be set when it is installed, but it see...

How to prompt and open hyperlink a

<br />The countless information on the Inter...

Record the process of connecting to the local Linux virtual machine via SSH

Experimental environment: Physical machine Window...

jQuery+Ajax to achieve simple paging effect

This article shares the specific code of jquery+A...

Next.js Getting Started Tutorial

Table of contents Introduction Create a Next.js p...

Summary of some reasons why crontab scheduled tasks are not executed

Preface I recently encountered some problems at w...

Steps for restoring a single MySQL table

When I was taking a break, a phone call completel...

Standard summary for analyzing the performance of a SQL statement

This article will introduce how to use explain to...

MySQL GROUP_CONCAT limitation solution

effect: The GROUP_CONCAT function can concatenate...

Analysis of rel attribute in HTML

.y { background: url(//img.jbzj.com/images/o_y.pn...