Databases 3 min read

Understanding MySQL Master‑Slave Replication: Architecture, Principles, and Diagrams

This article explains how MySQL master‑slave replication works, covering its role in high‑availability and read/write separation, the responsibilities of the master and slave servers, the IO and SQL threads, common replication topologies, and the step‑by‑step data flow from binlog to relay log.

Architect Chen
Architect Chen
Architect Chen
Understanding MySQL Master‑Slave Replication: Architecture, Principles, and Diagrams

MySQL is a core component of large‑scale architectures, and master‑slave replication (also called master‑slave synchronization) is a key technique for high availability, read/write separation, and backup recovery.

Replication architecture

The replication setup consists of a master server that handles write requests and records changes to the binary log (binlog), and one or more slave servers that receive and apply those changes, typically serving read traffic or acting as failover nodes.

Each slave runs two threads:

IO Thread (Slave_IO) : establishes a TCP connection to the master, pulls binlog events, and writes them to the local relay log.

SQL Thread (Slave_SQL) : reads the relay log and re‑executes the events on the slave’s data files.

Replication topologies can be one‑master‑multiple‑slaves, chained replication (master → slave A → slave B), or circular/multi‑master setups that require additional conflict‑resolution mechanisms.

How replication works

The master writes every data‑changing DDL/DML operation to its binlog.

The slave’s IO thread connects to the master, fetches the binlog contents, and stores them in a local relay log.

The slave’s SQL thread reads the relay log sequentially and applies the events to the slave’s data files, achieving data consistency with the master.

In simple terms, the master records all changes in the binlog; the slave reads those records and re‑executes them, keeping the datasets synchronized.

Illustrative diagram

+-------------------+                                 
| Master            | server‑id = 1          
| binlog enabled    |                         
| BinlogDumpThread  |                         
+-------------------+                         
          |                                   
          v                                   
+-------------------+   +-------------------+   
| Slave 1           |   | Slave 2           |   
| server‑id = 2     |   | server‑id = 3     |   
| IO Thread         |   | IO Thread         |   
| SQL Thread        |   | SQL Thread        |   
| relay‑log          |   | relay‑log          |   
+-------------------+   +-------------------+
Database ArchitectureMySQLbinlogmaster‑slavereplicationRelay Log
Architect Chen
Written by

Architect Chen

Sharing over a decade of architecture experience from Baidu, Alibaba, and Tencent.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.