What is the binary log (binlog) in MySQL?
IntermediateConceptMySQL
Answer
Short answer
The binary log records every change made to the data (inserts, updates, deletes, schema changes) in order. It's used for replication (replicas replay it) and point-in-time recovery (restore a backup, then replay the binlog up to just before a mistake).
Commands
SHOW VARIABLES LIKE 'log_bin'; -- ON?
SHOW BINARY LOGS; -- list files and sizes
SHOW MASTER STATUS; -- current file + position (8.4: SHOW BINARY LOG STATUS)
PURGE BINARY LOGS BEFORE NOW() - INTERVAL 3 DAY;
# my.cnf
binlog_expire_logs_seconds = 604800 # keep 7 days
binlog_format = ROW # recommended
Point-in-time recovery example
Someone ran DELETE FROM orders at 14:32.
mysql shop < nightly_backup.sql # restore last night
mysqlbinlog --start-position=<from backup> --stop-datetime="2026-11-26 14:31:59" \
binlog.000123 binlog.000124 | mysql shop # replay up to the mistake
Common production issue
Disk fills up because binlogs were never expired → set binlog_expire_logs_seconds.
What to say in the interview
"The binlog is MySQL's ordered change log. Replicas replay it and we use it for point-in-time recovery by restoring a backup and replaying binlogs up to just before an incident. I set a retention period so binlogs don't fill the disk."
More on MySQL
How do you set up MySQL and log in to it?BeginnerHow do you create a database, a table and see data in MySQL?BeginnerHow do you create a MySQL user for an application and give it permissions?BeginnerHow do you back up and restore a MySQL database?BeginnerWhat is a relational database?BeginnerWhat is the difference between a database, a table, a row and a column?Beginner