Safe to Delete

MySQL Binary Logging Files (/var/lib/mysql/binlog.*)

Quick Answer: MySQL binlog.* files store transaction replication logs. Purging old binary logs via PURGE BINARY LOGS is safe and recovers server storage.

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 (.ibd InnoDB files) remain 100% safe.
  • Safety rule: Never delete binlog.* files directly using OS rm commands while MySQL is running; always use PURGE BINARY LOGS or configure binlog_expire_logs_seconds.

How to Safely Clean Up MySQL Binary Logs

  1. Log into MySQL console as root:
    mysql -u root -p
  2. 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

Discussion

Loading authentication...

Related in developer

The AI Engineer's Model Disk Cleanup Guide: Hugging Face, Ollama & PyTorch

The ultimate 1,200-word field guide for AI developers and local LLM hobbyists to reclaim 200GB+ from Ollama, Hugging Face, PyTorch, and vLLM model weights.

Safe to Delete

Android Studio System Index Cache (AndroidStudio Cache)

Android Studio caches Gradle project indexes, VFS caches, and compiler artifacts. Invalidate and clear is safe.

Safe to Delete

Ansible Automation Temp & Fact Cache (~/.ansible/tmp)

Ansible stores temporary playbook execution modules and target host fact JSON caches in ~/.ansible/tmp. Clearing Ansible tmp is safe.

Safe to Delete
Back to all files