Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Summary of the principle of MySQL Master-Slave replication based on position of mysql

2025-04-06 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

1. Introduction to master-slave replication

MySQL master-slave replication is to copy data from one MySQL instance (Master) to another MySQL instance in real time.

In the example (slave), and this replication is an asynchronous replication process.

The implementation of the entire replication operation is mainly done by three processes, two of which are in Slave (sql_thread and

IO_thread), another process on the Master.

2. Principle and mechanism of master-slave replication

To implement replication, you must first turn on the binary log (bin-log) function on the Master side, otherwise it cannot be implemented.

Because the whole replication process is actually Slave getting the log from the Master and then completely sequential on himself.

Perform various actions recorded in the log.

The basic process of replication is as follows:

1)IO_thread above Slave connects to Master and requests a log file from a specified location (or

log content after the initial log;

2)After receiving the IO_thread request from Slave, the Master passes the IO process responsible for replication according to the request.

Read the log information after the specified log location and return it to the IO_thread of Slave. Return information except

In addition to the information contained in the log, it also includes the information returned this time has been sent to the bin-log file of the Master side and

bin-log pos;

3)After receiving the message, the IO_thread of Slave adds the received log contents to the IO_thread of Slave in turn.

Relay-log file, and record the bin-log file name and location of the read Master side to

master-info file, so that the next time I read it, I can clearly tell the Master,"I need to get from a certain

bin-log where to start the next log content, please send me ";

4)Sql_thread of Slave will parse relay-log immediately after detecting new content added to relay-log.

The contents of become those executable contents when actually executed on the Master side, and are executed in this database.

3. Master-slave copy schematic diagram

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report