MySQL master-slave replication principle (transfer) MySQL master-slave replication principle

This article is reprinted from https://blog.csdn.net/php_younger/article/details/59673879

MySQL master-slave replication principle

master-slave form

 
MySQL master-slave replication is flexible
  • One master and one slave
  • master master replication
  • One master and multiple slaves---extend the performance of system reading, because the reading is read from the library;
  • Multiple masters and one slave---support from 5.7
  • Cascade replication---
 
 
 
Use and Conditions

 
mysql master-slave replication purpose
  • Real-time disaster recovery for failover
  • Read-write separation, providing query services
  • Backup to avoid business impact
 
Master-slave deployment prerequisites:
  • The main library opens the binlog log (set the log-bin parameter)
  • The master and slave server-id are different
  • The slave library server can connect to the master library
 
master-slave principle

MySQL master-slave replication principle
 
 

 

Generate two threads from the library, one I/O thread and one SQL thread;
 
The i/o thread requests the binlog of the main library, and writes the obtained binlog log to the relay log file;
The main library will generate a log dump thread to transmit binlog to the slave library i/o thread;
 
The SQL thread will read the log in the relay log file and parse it into specific operations to achieve consistent master-slave operations and consistent data in the end
 
Problems and Solutions

 
Problems with mysql master-slave replication:
  • After the main database goes down, data may be lost
  • There is only one sql thread in the slave library, the main library has a lot of writing pressure, and the replication is likely to be delayed
 
Solution:
  • Semi-synchronous replication---solve the problem of data loss
  • Parallel replication - solve the problem of replication delay from the library

 

Parallel replication

 
mysql parallel replication
  • New in Community Edition 5.6
  • Parallel refers to the multi-threaded apply binlog from the library
  • Binlog is applied in parallel at the library level, and data changes in the same library are still serial (version 5.7 parallel replication is based on transaction groups)
set up
set global slave_parallel_workers=10;
Set the number of sql threads to 10

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324527216&siteId=291194637