MySQL Binary Log Retention Checklist
Binary logs record database changes and are useful for replication and point-in-time recovery. But unmanaged binary logs can grow until the disk fills up and MySQL becomes unstable.
Core principle
Binary logs are recovery tools, not permanent archives. Keep them long enough for recovery and replication needs, but not forever on a small VPS.
Checklist
- Check whether binary logging is enabled.
- Check binary log location.
- Check binary log disk usage.
- Check replication or recovery requirements.
- Check current expiration policy.
- Set retention intentionally.
- Never delete active binary logs manually.
- Purge old logs using MySQL commands.
- Monitor disk after retention change.
- Document recovery tradeoff.
Reusable lesson
This applies to database servers, replication readiness, point-in-time recovery, disk growth management and backup architecture.
When to Use This Checklist
Use this checklist when MySQL binary logs consume disk space or when designing replication and recovery retention.
Required Tools
MySQL admin access, SSH access, disk usage tools, backup policy, replication status if used
Before You Start
Do not delete binary log files manually from the filesystem. Use MySQL purge commands and understand recovery impact.
Structured Checklist Steps
- Check binlog state.
- Find binlog path.
- Check disk usage.
- Check replication needs.
- Check expiration.
- Set retention.
- Avoid manual deletion.
- Purge safely.
- Monitor disk.
- Document tradeoff.
Verification Steps
- Binary log policy is known.
- Disk usage is controlled.
- Recovery requirement is respected.
- No active log is deleted manually.
- Retention decision is documented.
Rollback Plan
If binary log cleanup breaks replication or recovery assumptions, stop purging and restore from backup or rebuild replica according to the recovery plan.
Common Mistakes
- Deleting binlog files manually.
- Keeping binlogs forever on small disk.
- No retention policy.
- Ignoring replication requirements.
- Not documenting recovery impact.
Related Commands
mysql -u root -p -e "SHOW VARIABLES LIKE 'log_bin';"
mysql -u root -p -e "SHOW BINARY LOGS;"
mysql -u root -p -e "SHOW VARIABLES LIKE 'binlog_expire_logs_seconds';"
sudo du -sh /var/lib/mysql/*bin* 2>/dev/null
mysql -u root -p -e "PURGE BINARY LOGS BEFORE NOW() - INTERVAL 7 DAY;"