This MySQL statement deletes the binary logs from a master server.


Below is the syntax for this command. Text within square brackets (i.e, [ and ] ) are optional. Choices are separated by bars (i.e, | ). Ellipses preceded by a comma indicates a repeating pattern. Ellipses before or after syntax are used to highlight a relevant except from the larger syntax. Text displayed in italic letters represent text that should be replaced with the specific names related to the database (e.g., column with the name of the column).

PURGE {MASTER|BINARY} LOGS {TO 'log_filename'|BEFORE 'date'}


This MySQL statement deletes the binary logs from a master server running replication. The keywords MASTER and BINARY are synonymous and one is required for the statement. Log files are deleted sequentially from the starting log file to the one named with the TO clause, or up until (but not including) the date named with the BEFORE clause.


Here is an example of each method using this MySQL statement:

PURGE MASTER LOGS TO 'log-bin.00110';
PURGE MASTER LOGS BEFORE '2004-11-03 07:00:00';

Before running this statement, it would be prudent to make a backup of the logs. Then use the MySQL statement, SHOW SLAVE STATUS on each replication slave to determine which logs the slaves are reading, and run SHOW BINARY LOGS on the master server to get a list of log files. The oldest log file in the list is the one that will be purged. If the slaves are current, they shouldn't be reading this log file. If they still are, you might not want to purge them. If you find that your log files aren't being rotated very often, you can set the system variable expire_logs_days to shorten the amount of time before new log files are created and old ones archived.