Home  >  Article  >  Database  >  What is the use of mysql log files?

What is the use of mysql log files?

青灯夜游
青灯夜游Original
2019-05-06 11:37:085043browse

The functions of mysql log files: 1. Can record modification information of physical data pages; 2. Can logically restore data to the state before the transaction; 3. Can record the database in the form of binary files operations; 4. It can record error-related information; 5. It can fetch events from binary files in the main server, etc.

What is the use of mysql log files?

Recommended: "mysql tutorial"

MySQL log files can be divided into: redo log ( redo log), rollback log (undo log), binary log (binlog), error log (errorlog), slow query log (slow query log), general query log (general log), relay log (relay log). The following article will give you a brief introduction to these MySQL log files. I hope it will be helpful to you.

1. Redo log (redo log)

The redo log is a log in a physical format that records the modification information of the physical data page. The redo log is written sequentially to the physical file of the redo log file.

Redo logs can ensure the durability of transactions. This prevents dirty pages from being written to the disk at the time of failure. When the mysql service is restarted, redo is performed based on the redo log to achieve transaction durability.

2. Rollback log (undo log)

The rollback log is a log in a logical format. When undo is executed, the data is only transferred from the logical It is different from the redo log in that it is restored to the state before the transaction rather than operating on the physical page.

The rollback log saves a version of the data before the transaction, which can be used for rollback. It can also provide multi-version concurrency controlled reading (MVCC), that is, non-locking reading

3. Binlog (binlog)

Binary log is a log in a logical format, which records operations in the database in the form of binary files, but does not record query statements. It can be simply thought of as the sql statement in the executed transaction; but it is not as simple as the sql statement, but includes the reverse information of the executed sql statement (addition, deletion, modification), which means that delete corresponds to delete itself and The reverse insert; update corresponds to the version information before and after update is executed; insert corresponds to the information of delete and insert itself.

Binary logs can be used for replication. In master-slave replication, the slave library uses the binlog on the master library to replay to achieve master-slave synchronization; used for point-in-time restoration of the database.

4. Error log (errorlog)

The error log records the start and stop of mysqld, as well as information about errors that occur during the operation of the server. By default, the system's error logging function is turned off, and error messages are output to standard error output.

5. Slow query log (slow query log)

The slow log records query statements that take too long to execute and do not use indexes, and report errors for select, update, delete, and For insert statements, the slow log will only record statements that are successfully executed.

6. General query log (general log)

records every query or command received by the server, regardless of whether these queries or commands are correct or even incorrect. If it contains syntax errors, the general log will record them in the format of {Time, Id, Command, Argument}. Precisely because the mysql server needs to continuously record logs, turning on General log will cause a lot of system overhead. Therefore, Mysql turns off the General log by default.

7. Relay log (relay log)

The relay log is similar to binary; it can be used in replication architecture, and the slave server is used from the master server Binary file to retrieve events.

Note:

The redo log and rollback log are closely related to transaction operations, and the binary log is also related to transaction operations. These three types of logs are Understanding transaction operations in MySQL is of great significance.

The above is the detailed content of What is the use of mysql log files?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn