Mysql database processing of binlog (1)

Source: Internet
Author: User

BinlogYesMysqlLogs that are printed in binary format are not encrypted by default and are not compressed. Each normal binlog File Header has a four-byte mark with a value of 0xfe 0x62 0x69 0x6e. LOG_EVENT is the unit in binlog. Normally, binlog increases by LOG_EVENT. Except for the header tag, binlog is a LOG_EVENT sequence. Each LOG_EVENT is an independent unit and has no mutual reference relationship. It also has its own binary header, which records the time stamp, type tag, and other description information.

Mysql encapsulates the implementation of disk operations in the IO_CACHE structure, which facilitates our research and description of binlog. If not specifically described in the following article, read/write binlog and read/write IO_CACHE have the same meaning. To understand the binlog Writing Process of mysql, you can find an SQL statement to track the processing process. Take update as an example. In the simplest case, mysql will first call the ha_update_row interface opened for the storage engine, but execute binlog_query to write the binlog.

The reason for this is that, in the scenario of master-slave backup, if the binlog is successfully written to the master database and crash is executed during update, the slave database may execute update successfully, after the master database is restarted, it is inconsistent with the data in the slave database. If the update operation occurs on a transactional table, the open interface ha_autocommit_or_rollback will be executed after the binlog is written. The storage engine determines the operation result.

In the scenario of master-slave backup, the master database is equivalent to the server, the slave database is equivalent to the client, and both parties adopt tcp short connections. The slave database sends a log reading request. The master database receives the request, reads the local binlog, and sends the request to the slave database. The relay log is used to receive logs from the database, perform simple verification, and then write local logs. A thread is responsible for the process from the database, which is called a synchronous io thread. There is also a thread in the slave database, called a synchronous SQL thread. It regularly reads relay logs, parses and executes the synchronized SQL statements.

Below are a few questions:

1. What is the binlog format?

Binary Sequence storage, not encrypted, not compressed.

2. Does binlog use WAL?

No.

3. Does the master database use the copy in memory to send the binlog?

Uncertain, it is likely that a copy is read from the disk and then sent.

4. Does relaylog use WAL?

Yes. After receiving logs from the database, the relay log is written first.

5. Are the SQL statements of binlog and relaylog consistent?

If the network transmission is correct and reliable, yes.


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.