Lesson 0008 · Internals & Performance
A second log — logical this time — ships every committed change to other servers. Whether a failover can lose your commit comes down to one word: async.
In Lesson 0007 the redo log made a commit survive a crash on one server. This capstone lesson scales that question out: how does a change reach other servers — read replicas, failover standbys? The answer is a different log for a different job: the binary log.
The binary log (binlog) records every committed change as a logical event (the row change or statement), at the server layer — separate from InnoDB's redo log. Its jobs are replication (feed the same changes to other servers) and point-in-time recovery. Contrast the redo log from 0007: physical, InnoDB-internal, and only for crash recovery on the same machine. Redo heals one server; the binlog copies one server to another.
| redo log (0007) | binary log (0008) | |
|---|---|---|
| Layer | InnoDB engine | Server (all engines) |
| Content | physical page changes | logical row/statement changes |
| Purpose | crash recovery (one server) | replication & PITR (across servers) |
| Lifetime | circular, reused after checkpoint | retained for replicas / backups |
Replication is binary-log based: the replica pulls the source's binlog and replays it, through two threads. — MySQL Manual: replication is "based on replicating events from the source's binary log."
The receiver (I/O) thread copies binlog events into the replica's relay log; the applier (SQL) thread executes them against the replica's data. Reads can then fan out across replicas while writes stay on the source. — MySQL Manual — Replication Threads
By default replication is asynchronous: the source commits and returns to the client without waiting for any replica. Fast — but it has a sharp edge. — MySQL Manual: "Replication is asynchronous by default."
Because the source doesn't wait, a transaction can be committed and acknowledged to your app, then the source crashes before the binlog reaches any replica. Promote a replica and that acknowledged commit is gone. Async replication means a failover can lose committed data — the distributed version of the durability question from 0007.
Semisynchronous replication narrows that window: a commit on the source blocks until at least one replica acknowledges it has received the transaction's events (written and flushed to that replica's relay log) — not that it has applied them. — MySQL Manual: "a thread that performs a transaction commit on the source blocks and waits until at least one semisynchronous replica acknowledges that it has received all events for the transaction… it requires only an acknowledgement from the replicas, not that the events have been fully executed."
Semisync guarantees that if the source crashes, every committed transaction has reached at least one replica — so a failover won't silently lose it. The cost is added commit latency (one network round-trip). Note the subtlety: "received" means in the relay log, not yet applied — so a replica may still be a moment behind on applying even though it has safely received the change.
Answer from memory — effortful recall is what builds retention. Feedback is immediate.
The binary log's two jobs are:
Compared with the binary log, the redo log is:
MySQL replication is, by default:
On the replica, the binlog is copied to the relay log by the:
With asynchronous replication, a source failover can:
Semisync makes the source's commit wait until a replica has:
A committed change survives a single-server crash via the:
You can explore the binlog on your single server — no replica needed.
-- 1) Is binary logging on? (default ON in 8.0)
SHOW VARIABLES LIKE 'log_bin';
-- 2) The binlog files and the current position
SHOW BINARY LOGS;
SHOW BINARY LOG STATUS; -- (SHOW MASTER STATUS on older 8.0.x)
-- 3) Make a change, then read the events it logged
UPDATE people SET city = 'BINLOG' WHERE id = 1;
SHOW BINLOG EVENTS IN 'binlog.000001' LIMIT 20; -- use your filename from step 2
-- 4) The row-vs-statement format that shapes those events
SHOW VARIABLES LIKE 'binlog_format'; -- ROW (default), STATEMENT, or MIXED
Each committed transaction appears as a group of events in the binlog, tagged with the
position a replica would resume from. With binlog_format = ROW (the safe default)
you'll see the actual row images that changed — the logical feed a replica replays. On a
real replica, SHOW REPLICA STATUS\G would show the receiver/applier threads and the
replication lag. Bring me a SHOW BINARY LOG STATUS and we'll read the position.
MySQL 8.0 Reference Manual — Replication, then Semisynchronous Replication for the async-vs-semisync trade-off, and The Binary Log for formats and PITR.