Pcornel
Databases · MariaDB / MySQL

MySQL Binary Log and Replication

Cheat sheet · https://pcornel.dk/topic.php?topic=6178

Back to the Topic

Answer

The binary log records data changes in MySQL/MariaDB; replicas read it to replicate, and it enables point-in-time recovery.

Remember

Use row-based format and GTIDs. Keep binlogs long enough for replicas and backups (expire settings). Replica errors show in SHOW REPLICA STATUS.

First checks

  • SHOW VARIABLES LIKE 'log_bin'; — first check for this topic
  • psql -c "SELECT now(), version();" — PostgreSQL reachable and version
  • mysql -e "SELECT NOW(), VERSION();" — MariaDB/MySQL reachable and version
  • sqlcmd -S <server> -Q "SELECT @@VERSION" — SQL Server reachable and version

Commands

SHOW REPLICA STATUS

Verify in this order

primary writes binlog → replica IO thread copies → SQL thread applies

Where it usually breaks

A replica stopped on an error keeps falling behind silently unless monitored.

Read-only verification commands unless stated otherwise. Confirm syntax for your platform and release. Full reference: https://pcornel.dk/topic.php?topic=6178

Confirmation

Confirm action

Continue?