Bottom Line: It is safe to purge old MySQL binary logs using the SQL PURGE BINARY LOGS command. Deleting historical binlogs will NOT corrupt active MySQL databases or table data.
What are MySQL Binary Log Files?
Located at /var/lib/mysql/ on Linux (or C:\ProgramData\MySQL\MySQL Server X.X\Data), files named binlog.000001, binlog.000002, or mysql-bin.* are created by MySQL and MariaDB.
Binary logs record all SQL statements that update database content (INSERT, UPDATE, DELETE) for:
- Replication: Syncing database edits to replica follower servers.
- Point-in-Time Recovery: Restoring database states to exact timestamps.
On high-traffic web servers or database clusters, MySQL binary logs expand rapidly, consuming 20 GB to 200 GB+ of drive space.
Can You Delete MySQL Binary Logs?
✅ Yes, it is safe to purge via SQL commands.
- No table data loss: Active database tables (
.ibdInnoDB files) remain 100% safe. - Safety rule: Never delete
binlog.*files directly using OSrmcommands while MySQL is running; always usePURGE BINARY LOGSor configurebinlog_expire_logs_seconds.
How to Safely Clean Up MySQL Binary Logs
Method 1: Purge via MySQL CLI (Recommended)
- Log into MySQL console as root:
mysql -u root -p - Purge binary logs older than 3 days:
PURGE BINARY LOGS BEFORE NOW() - INTERVAL 3 DAY;
Method 2: Configure Automatic Expiration in my.cnf
Add this line to /etc/mysql/my.cnf to automatically expire binary logs after 7 days (604800 seconds):
[mysqld]
binlog_expire_logs_seconds = 604800
Related Guides
- Learn about deleting [Redis dump.rdb file].
- How to clean up [PostgreSQL pg_wal logs].
- Check if you can clean Linux /var/log.
Discussion
Loading authentication...