The principle of master-slave replication of Mysql database

The role of master and slave

1. Real-time disaster recovery: a master database is down, and the slave database is enabled for failover

2. Read and write separation: the master server is only used for write operations, and the slave server is only used for reading, which supports greater concurrency

3. Backup: can solve the problem of data loss and avoid affecting business

Master-slave principle

1. The main library receives the update command, executes the update operation, and generates binlog

2. Open an I/0 thread from the library salve to establish a long connection between the main library dump_thread

3. After the master node receives the I/O request from the slave node, it returns the specified log and log information after the specified location through the dump thread, and returns it to the slave node

The main library dump_thread reads the binlog from the local and transmits it to the slave library

4. After obtaining the binlog from the main library from the library, store it locally to become a relay log (relay log), and save the read binary log (bin-log) file name and location to the master-info file

5. The sql_thread thread reads the relay log analysis, executes the command to update the data

Guess you like

Origin blog.csdn.net/Q274948451/article/details/109409858