PURGE BINARY LOGS TO 'mysql-bin.010'; PURGE BINARY LOGS BEFORE '2008-04-02 22:46:26';
BINARY and MASTER are synonyms. This statement is safe to run while slaves are replicating. If you have an active slave that currently is reading one of the logs you are trying to delete, this statement does nothing and fails with an error. However, if a slave is dormant and you happen to purge one of the logs it has yet to read, the slave will be unable to replicate after it comes up.
To safely purge logs:
- On each slave server, use SHOW SLAVE STATUS to check which log it is reading.
- Obtain a listing of the binary logs on the master server with SHOW BINARY LOGS.
- Determine the earliest log among all the slaves. If all the slaves are up to date, this is the last log on the list.
- Make a backup of all the logs you are about to delete. (This step is optional, but always advisable.)
- Purge all logs up to but not including the target log.
You can also set the expire_logs_days system variable to expire binary log files automatically after a given number of days (see Section 5.1.3, “System Variables”). If you are using replication, you should set the variable no lower than the maximum number of days your slaves might lag behind the master.