MySQL

Purge binary logs in MySQL

Please do not just delete them in the OS.

You need to let mysqld do that for you. Here is how mysqld manages it:

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:

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

SHOW SLAVE STATUS\G
This is critical. When you run SHOW SLAVE STATUS\G, you will see two binary logs from the Master:

Master_Log_File
Relay_Master_Log_File
When replication has little or no lag these are usually the same value. When there is a lot of replication lag, these values are different. Just to make it simple, choose whatever Relay_Master_Log_File is, and go back to the Master and run

That way, replication is not interrupted.

Leave a Reply

Your email address will not be published. Required fields are marked *