MySQL in the redo log (redo log), the rollback log (undo log), and the binary log (binlog) a brief summary ...

There are six in MySQL log files are: redo log (redo log), the rollback log (undo log), the binary log (binlog), error log (errorlog), slow query log (slow query log), General Inquiries log (general log), the relay log (relay log).
Which redo logs and rollback logs and transaction operations closely related to the binary log also has a certain relationship with transactional operations, three log for understanding transaction operations in MySQL has an important significance.

Here briefly summarize these three log has a certain relevance.

Redo log (redo log)

  • Role:
    to prevent the failure point in time, there are dirty pages
    are not written to disk (after the transaction commits, before data is written to disk is down), when the restart mysql services, according to redo redo log, so as to achieve affairs persistent this feature.
  • Content:
    physical format log record information is to modify the physical page of data, which is written to redo log of the redo log file to the order of the physical file.
  • Generation opportunity:
    to produce redo log after the start of the transaction, the redo log off the disk as the transaction is not only written submissions, but during the execution of a transaction, began to write redo log file.
  • The timing of release:
    When the corresponding transaction dirty pages are written to disk, redo log mission is finished, redo log space occupied can be reused (covered).
Buffer Innodb_log_buffer

There is a redo log buffer Innodb_log_buffer, Innodb_log_buffer default size is 8M, Innodb storage engine first redo log write Innodb_log_buffer, and then will be Innodb log log buffer is flushed to disk in one of three ways:

  1. Master Thread execute once per second refresh Innodb_log_buffer to redo log files
  2. Each transaction will refresh time of submission.
  3. When the redo log buffer is less than half the available space, redo log cache is flushed to the redo log files.

Therefore, redo log disk write, not necessarily with the transaction submitted only written to the redo log files, but with the start of the transaction, and gradually began.

Rollback log (undo log)

  • Role:
    Save a version of the transaction occurs before the data can be used to roll back.
  • Content:
    logical format of the log, the undo in the implementation, only the data from the logical-to recover the state before the transaction, rather than the operating implement from the physical page, and this is different from the redo log.
  • Generation opportunity:
    Before the beginning of the transaction, the current version is generated undo log, undo redo will also have to ensure the reliability of undo log.
  • The timing of release:
    When the transaction is committed, undo log and can not be removed immediately, but to be put in to clean up the list, the purge thread determines whether there is other information versions use a transaction before the transaction on a table in the undo segment, decide whether you can clean undo log log space.

Binary log (binlog)

  • effect:
    1. For replication, replication from the master, binlog replayed from the library using the master library, to achieve master-slave synchronization.
    2. Reducing the time point based on the database.
  • Content:
    the logical format of the log, you can simply think that is a transaction executed in the sql statement.
  • Generation opportunity:
    when the transaction commits, one-time transaction sql statement (a thing may correspond to multiple sql statements) recorded in the binlog in accordance with a certain format.
    Here it is clear that the difference redo log redo log is not necessarily when the transaction was submitted flushed to disk, redo log is written to disk gradually began after the start of the transaction.
  • The timing of release:
    binlog default hold time is configured by the parameters expire_logs_days, that is inactive for the log file, after several days expire_logs_days configured to generate over time, will be automatically deleted.

MySQL through the two-phase commit process to complete the transaction consistency, that redo log binlog consistency and, in theory, is to write redo log, write binlog, two logs are successfully submitted (brush into the disk), transaction truly complete.

Reproduced in: https: //www.jianshu.com/p/59c20fdd58ba

Guess you like

Origin blog.csdn.net/weixin_34279579/article/details/91268722