VillageSQL is a drop-in replacement for MySQL with extensions.
All examples in this guide work on VillageSQL. Install Now →
Enabling Binary Logging
Binary logging is enabled by default in MySQL 8.0. To verify:my.cnf / my.ini:
log_bin is set, MySQL names binlog files as mysql-bin.000001, mysql-bin.000002, etc., with an index file (mysql-bin.index) listing them all.
Binary Log Formats
MySQL supports three binlog formats:| Format | What’s logged | Replication safety | Log size | Performance impact | Best for |
|---|---|---|---|---|---|
ROW | Actual before/after row data for each affected row | Safest — deterministic regardless of replica state | Largest (grows with data volume, especially bulk updates) | Highest write overhead on source | Production replication; PITR; CDC/change data capture |
STATEMENT | The SQL statement that caused the change | Unsafe for non-deterministic functions (RAND(), UUID(), NOW()) | Smallest | Lowest overhead | Read-heavy workloads where log size matters and all statements are deterministic |
MIXED | STATEMENT by default; switches to ROW for unsafe statements | Safe (ROW used when needed) | Medium | Medium | Legacy setups migrating from STATEMENT; not recommended for new deployments |
ROW format is the recommended default. It replicates correctly even when non-deterministic functions like RAND() or UUID() are involved. The downside is larger log files — a single UPDATE touching millions of rows produces one statement in STATEMENT format but one row event per affected row in ROW format.
When to enable binary logging and which format to choose
Binary logging is enabled by default in MySQL 8.0+. The question is usually which format to use and whether to leave it on at all.| Scenario | Recommendation |
|---|---|
| Running any replica | Enable binary logging, use ROW format — it’s required for Group Replication and recommended for standard replication |
| Point-in-time recovery needed | Enable binary logging; format doesn’t affect PITR capability, but ROW gives the most precise replay |
| Change data capture (CDC) with Debezium, Kafka Connect, etc. | Enable binary logging, ROW format required — CDC tools read row-level events directly |
| Standalone dev/test instance, no replication, no PITR | Disabling binary logging (--skip-log-bin) reduces write overhead and disk usage |
| Very high write throughput, log size is a concern | Consider binlog_row_image = MINIMAL (logs only changed columns) rather than switching to STATEMENT |
| Auditing or compliance | ROW format with binlog_row_image = FULL (the default) gives a complete before/after record |
Listing and Viewing Binary Logs
List all binary log files:mysqlbinlog
Themysqlbinlog tool decodes binary log files into human-readable SQL. It’s used for point-in-time recovery and auditing:
Point-in-Time Recovery
Combining a full backup with binary logs lets you restore to any point in time after the backup was taken. Typical workflow:- Take a full backup with
mysqldump --single-transaction --source-data:
--source-data=2 writes the binlog filename and position as a comment in the dump. This is your recovery starting point.
- Restore the full backup:
- Find the binlog file and position from the dump:
- Replay binlogs from that position up to just before the event you want to undo:
Managing Binary Logs
Manually purge old binary logs:binlog_expire_logs_seconds (MySQL 8.0+) or expire_logs_days:
rm — use PURGE BINARY LOGS so the index file stays consistent.
Frequently Asked Questions
Does binary logging affect write performance?
Yes, modestly. ROW format logging adds overhead proportional to the amount of data changed. For write-heavy workloads, the overhead is typically 5–15%. It’s almost always worth it for the recovery and replication capabilities it enables.Can I skip binary logging for a specific session?
BINLOG_ADMIN or SUPER privilege.
How do I know how much disk space my binary logs are using?
du -sh /var/log/mysql/mysql-bin.*
Troubleshooting
| Problem | Solution |
|---|---|
| Binary log files filling up disk | Set binlog_expire_logs_seconds or run PURGE BINARY LOGS BEFORE — never rm the files directly |
mysqlbinlog output is unreadable for ROW format | Add --verbose (or -v) to decode row events into pseudo-SQL |
| Point-in-time recovery missed some changes | Check that all binlog files in the range were included — gaps in the file list leave holes in the replay |
ERROR: Binary logging not possible in replication | Replica may need log_bin enabled and a unique server_id — both are required |
| High replication lag | ROW format produces more data — check replica I/O and SQL thread lag with SHOW REPLICA STATUS\G |

