The following articles mainly describe how ELE. Me deletes the MySQL BIN-LOG correctly, as well as examples of the actual code used in the MySQL BIN-LOG, the following is a description of the specific solution. I hope it will help you in your future study.
- PURGE {MASTER | BINARY} LOGS TO 'log_name'
- PURGE {MASTER | BINARY} LOGS BEFORE 'date'
Deletes all binary logs listed in the log index before the specified log or date. These logs will also be deleted from the list recorded in the LOG index file, so that the given LOG becomes the first.
For example:
- PURGE MASTER LOGS TO 'MySQL-bin.010';
- PURGE MASTER LOGS BEFORE '2008-06-22 13:00:00';
Clear binlog 3 days ago
- PURGE MASTER LOGS BEFORE DATE_SUB( NOW( ), INTERVAL 3 DAY);
The date argument for the BEFORE variable can be in the 'yyyy-MM-DD hh: mm: ss' format. Both MASTER and BINARY are synonyms.
If you have an active slave server that is currently reading one of the logs you are trying to delete, this statement does not work, but fails with an error. However, if the slave server is slave and you happen to have cleared one of the logs it wants to read, the slave server cannot be copied after it is started. This statement can be run safely when the slave server is being copied. You do not need to stop them.
To clear logs, follow these steps:
1. Use show slave status on each SLAVE server to check which log it is reading.
2. Use show master logs to obtain a series of LOGS on the MASTER server.
3. Identify the earliest logs among all slave servers. This is the target log. If all slave servers are updated, this is the last log in the list.
4. Back up all the logs that you want to delete the MySQL BIN-LOG. This step is optional, but is recommended .)
5. Clear all the logs, but do not include the target logs.