Bobby's Blog

MySQL how to delete old binary logs

bobby-iliev-mysqlbinlog

You should not just delete your MySQL old binary logs.

You need to let mysqld do that for you.

The file mysql-bin.[index] keeps a list of all binary logs mysqld has generated and auto-rotated. The mechanisms for cleaning out the binlogs in conjunction with mysql-bin.[index] are:

Or:

These will clear all binary logs before the binlog or timestamp you just specified.

For example, if you run

this will erase all binary logs before mysql-bin.000223.

If you run:

this will erase all binary logs before midnight 3 days ago.

If you want to have binlog rotated away automatically and keep 3 days woth, simply set this:

then add this to /etc/my.cnf

and mysqld will delete them logs for you.

This is pretty much it!

Source


About the author

Bobby

Linux System Administrator