How to implement MySQL read-write separation? How does MySQL master slave replication work? How to solve the delay of MySQL master/slave synchronization?

How to implement MySQL read-write separation?

Based on master-slave replication, one master, multiple slave, and then we just write to the master, and then the master will automatically synchronize data to the slave, and read data from the slave.

How does MySQL master slave replication work? How to solve the delay of MySQL master/slave synchronization?

Mysql primary/secondary replication Purpose: Real-time DISASTER recovery for failover. Read/write separation and query services. Back up data to avoid service impact

The master/slave replication principle of mysql is as follows: The master database writes changes to the binlog log. After the slave database connects to the master database, the slave database has an I/O thread that copies the binlog logs of the master database to its own host and writes them to a relay log. Then an SQL thread from the slave library reads the binlog from the slave log and executes the contents of the binlog, i.e. executes the SQL locally to ensure that it is the same as the data from the master library. The I/O thread requests the master binlog and writes the resulting binlog to the relay log file. The primary library generates a log dump thread to pass binlogs to the secondary LIBRARY I/O thread. The SQL thread will read the logs in the relay log file and parse them into specific operations to achieve the consistency of the master and slave operations and the consistency of the final data.

Data loss: The primary database suddenly breaks down.