Databases 3 min read

Mastering MySQL Master‑Slave Replication: Architecture, Threads, and Setup

This article explains MySQL master‑slave replication, covering its purpose for high availability and read‑write separation, typical one‑master‑multiple‑slaves architecture, the binlog‑based synchronization mechanism, and the roles of the master’s dump thread and the slave’s I/O and SQL threads.

Architect Chen
Architect Chen
Architect Chen
Mastering MySQL Master‑Slave Replication: Architecture, Threads, and Setup

What Is MySQL Master‑Slave Replication?

MySQL master‑slave replication (also called Master‑Slave Replication) is a widely used solution for database high availability and read‑write separation, allowing write operations to be concentrated on a primary server while read queries are distributed to secondary servers.

Typical Architecture

In production environments, a “one master, one slave” or “one master, multiple slaves” topology is common. The master (Master) handles all write operations such as INSERT, UPDATE, and DELETE. Each slave (Slave) handles all read operations ( SELECT). Changes on the master are captured in the binary log (Binlog) and streamed to the slaves in real time.

MySQL master‑slave architecture diagram
MySQL master‑slave architecture diagram

Replication Mechanism

The classic MySQL replication process can be summed up in one sentence: the master writes binlog entries, the slave pulls them with an I/O thread, and replays them with an SQL thread.

Binlog Dump Thread (Master) : When a slave connects, the master creates a Binlog Dump thread that streams the binary log to the requesting slave.

I/O Thread (Slave) : The slave starts an I/O thread that connects to the master, requests the binlog from a specific position, and writes the received events into a local Relay Log.

SQL Thread (Slave) : The SQL thread reads the Relay Log and executes the stored statements, ensuring the slave’s data stays consistent with the master.

MySQL replication thread diagram
MySQL replication thread diagram

This replication setup improves system read scalability, provides backup and disaster‑recovery capabilities, and reduces the load on the primary server.

high availabilityDatabase Architecturemaster-slave replicationbinary 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.