An Overview of MySQL Replication

Jonathan Seow
CodeX
Published in
7 min readJan 22, 2023

--

Photo by Shubham Dhage on Unsplash

Replication is copying data from a source database to one or many replica databases. This is commonly known as master-slave replication.

Because replication is one-way, write operations are only allowed on the source. Meanwhile, reads can distribute among the replicas.

Master-Slave Replication

Replication is commonly used to spread reads among multiple databases for scalability. Replicas also serve as data backup and can be used to replace the source database during failover.

In this article, we will talk about how MySQL replication works. Let’s get started! 🏃

Binary Log

A source database keeps track of its changes on a special file known as the binary log. It is a written record that includes row inserts, updates, deletes, and modifications to database structures.

The source database writes to its binary log

During replication, a replica connects to the source and asks for its binary log. Then, it executes the changes in the order they have happened. The replica will repeat the tables and…

--

--

Jonathan Seow
CodeX
Writer for

Software Engineer @ TikTok I also share byte-sized coding insights on my blog! https://www.thebytearray.com/