Lesson 4 of 9 · 27m
Binary Logs and Replication Mechanics
Understand binlog events, GTIDs, replication formats, positions, replica state, and the failure modes hidden behind a green replication check.
Replication is simple right up until the first time you need it during an incident. Then it becomes a set of exact questions: which transactions reached the replica, which coordinates are safe, which writes happened after failover, and whether the 'healthy' replica is actually consistent. Operators who understand the mechanics recover calmly. Operators who only know SHOW REPLICA STATUS fields by name improvise.
The binary log is the source of truth for movement
The binary log records committed changes in transaction order. Replicas connect to the source, pull events, write them into relay logs, and apply them. In MySQL 8, replication terminology uses REPLICA and SOURCE, though older commands and output still appear in runbooks.
[mysqld]
server_id = 101
log_bin = mysql-bin
binlog_format = ROW
gtid_mode = ON
enforce_gtid_consistency = ON
binlog_expire_logs_seconds = 604800
sync_binlog = 1ROW format records row images rather than replaying statement text. It is the modern default because statement-based replication can be nondeterministic around functions, ordering, and data-dependent behavior.
GTIDs name transactions globally
A GTID looks like server_uuid:sequence. GTID-based replication tracks which transactions have executed, making failover and replica repositioning far safer than manually comparing file names and byte positions.
SELECT @@gtid_executed\G
SELECT @@gtid_purged\G
SHOW REPLICA STATUS\GThe crucial fields are Replica_IO_Running, Replica_SQL_Running, Seconds_Behind_Source, Retrieved_Gtid_Set, Executed_Gtid_Set, and error fields. Do not treat Seconds_Behind_Source as a precise lag measurement; it can be misleading when events are idle, delayed, or batched.
Replication is not backup
Replication copies committed mistakes just as faithfully as committed good work. DROP TABLE, an accidental wide update, or application corruption will often reach a replica quickly. Replication improves availability and read scaling. Backups protect recoverability. They solve different problems.
Semi-sync and durability are different choices
Asynchronous replication means the source commits without waiting for a replica. Semi-synchronous replication can wait for at least one replica to acknowledge receipt, reducing but not eliminating data-loss windows. It does not mean the transaction has necessarily been applied on the replica, only received according to the configured mode.
INSTALL PLUGIN rpl_semi_sync_source SONAME 'semisync_source.so';
INSTALL PLUGIN rpl_semi_sync_replica SONAME 'semisync_replica.so';Test plugin names and configuration against your exact MySQL distribution and version. Percona Server and MariaDB differ in operational details even when concepts overlap.
A green replica can still be a bad failover candidate
Consistency checking, schema drift, delayed replicas, read-only enforcement, and application compatibility all matter. read_only or super_read_only protects against accidental writes, but automation must know how to promote correctly. A replica receiving events is not necessarily caught up, consistent, or safe to write to.
Field notes
server_idmust be unique, but uniqueness alone does not make topology correct.- Row-based replication can produce large binlogs during wide updates and schema migrations.
- Replication filters are sharp edges; filtered writes often surprise future failover automation.
- Circular replication multiplies operational complexity and rarely removes the need for careful write ownership.
- Binlog retention is a recovery budget. Seven days means older point-in-time recovery is impossible without full backups.
Was this lesson helpful?