Is it safe to remove the BIN files that are generated by MySQL?

No, you should not delete them by hand.

If you delete them at the disk level, mysql will crash.

The command to remove them is:

PURGE BINARY LOGS TO 'mysql-bin.010';

Replace mysql-bin.010 with the last mysql-bin file that you wish to keep - typically the last one.

See the MySQL docs for more information.


There are a few reasons to use binary logging. In order of importance:

  1. Replication -- Slaves suck content from the master's binary log.
  2. Greater backup granularity -- Replay logs over a prior backup point.
  3. Query logging -- More efficient than the general query log for those occasional "what write query ran?" moments.

So there are three things to check before you delete any binary logs:

  1. Do you have any replication slaves and are they up to date?
    • If you delete a binary log before the slave has had a chance to pull it into it's relay log then it will be unable to proceed with replication. Also there can be freak instances where you may need to delete the relay log and spool again from the master.
  2. Are your backups in check?
  3. Will you need to review any queries that have been executed over that logging period?

If you are happy with the answers to all of those then go ahead and delete them with the PURGE command as noted by RageZ. Absolutely don't delete them by hand because MySQL likes to keep track of them. You can either use the syntax TO to specify a filename or BEFORE to specify a date. You can see which file MySQL currently has open with SHOW MASTER STATUS.

A much better approach, as kedar notes, is to use expire_logs_days. This will automatically perform the action of purging any binary logs that are older than N days.


you may also use expire_logs_days http://dev.mysql.com/doc/refman/5.0/en/purge-binary-logs.html