Purge Binary logs while using MySQL replication
While running a MySQL Master replication to a slave location, you might notice that the binlogs are stored on the filesystem and not cleaned up regularly. There are several ways to deal with this, I found this to be a nice approach;
Here you have a list of binlog known to the system
mysql> show binary logs; +------------------+-----------+ | Log_name | File_size | +------------------+-----------+ | mysql-bin.000001 | 602721 | | mysql-bin.000002 | 338 | | mysql-bin.000003 | 47207 | | mysql-bin.000004 | 56661 | | mysql-bin.000005 | 96460 | | mysql-bin.000006 | 117 | | mysql-bin.000007 | 4486 | | mysql-bin.000008 | 119368 | +------------------+-----------+ 8 rows in set (0.00 sec)
To Clean these up by hand you could execute :
mysql>PURGE BINARY LOGS BEFORE DATE_SUB( NOW( ), INTERVAL 0 DAY);
To Clean these up by hand if older then 7 Day’s
mysql>PURGE BINARY LOGS BEFORE DATE_SUB( NOW( ), INTERVAL 7 DAY);
Result would be :
mysql> show binary logs; +------------------+-----------+ | Log_name | File_size | +------------------+-----------+ | mysql-bin.000008 | 244883 | +------------------+-----------+ 1 row in set (0.00 sec)
Find here the CRON job created to delete binary logs older the 7 days on every sunday at 23:00.
# MySQL Clean-up the BINARY LOGs 00 23 * * 0 /usr/bin/mysql -e "PURGE BINARY LOGS BEFORE DATE_SUB( NOW( ), INTERVAL 7 DAY);

Comments are closed.