// shall I write some keywords here to boost search engine ranking?

Friday, June 13, 2008

Purge MySQL Binlog Safely

In order to setup MySQL replication, binlog must be enabled at master database. However, MySQL do not cleanup binlog generated automatically, and while you discover your server run out the disk space, the most common reaction is delete the binlog file from harddisk manually.

However, this is somehow risky as it do not update the *.index (for example, mydb-bin.index if the binlog is set as 'mydb-bin') file.

Fortunately MySQL do provide a way to handle these binlog - PURGE MASTER LOGS.

For example: If you issues command below:

PURGE MASTER LOGS TO 'mydb-bin.0023';

Then the binlog before 'mydb-bin.0023' will be deleted.

You may also do this:

PURGE MASTER LOGS BEFORE '2008-06-13 08:00:00'

All binlog prior to the date will be deleted.

1 comment:

Ivanator said...

You can also use the global variable expire_logs_days to perform automatic log bin removal.