Please do not just delete them in the OS.
You need to let mysqld do that for you. Here is how mysqld manages it:
The file mysql-bin.[index] keeps a list of all binary logs mysqld has generated and auto-rotated. The mechanisms for cleaning out the binlogs in conjunction with mysql-bin.[index] are:
PURGE BINARY LOGS TO ‘binlogname’;
PURGE BINARY LOGS BEFORE ‘datetimestamp’;
These will clear all binary logs before the binlog or timestamp you just specified.
For example, if you run
PURGE BINARY LOGS TO
this will erase all binary logs before mysql-bin.000223.
If you run
PURGE BINARY LOGS BEFORE DATE(NOW() – INTERVAL 3 DAY) + INTERVAL 0 SECOND;
this will erase all binary logs before midnight 3 days ago.
If you want to have binlog rotated away automatically and keep 3 days woth, simply set this:
mysql> SET GLOBAL expire_logs_days = 3;
then add this to /etc/my.cnf
and mysqld will delete them logs for you
SHOW SLAVE STATUS\G
This is critical. When you run SHOW SLAVE STATUS\G, you will see two binary logs from the Master:
When replication has little or no lag these are usually the same value. When there is a lot of replication lag, these values are different. Just to make it simple, choose whatever Relay_Master_Log_File is, and go back to the Master and run
PURGE BINARY LOGS TO ‘Whatever Relay_Master_Log_File Is’;
That way, replication is not interrupted.
Give it a try!!!
————–ERROR 1373 (HY000): Target log not found in binlog index————–
Purge Binary Logs Fails On Full Hard Drive
The purge binary command fails ñ no logs are deleted and the process hangs:
mysql> PURGE BINARY LOGS TO ‘BINLOG.000100’;
Checking the error log:
ERROR 3 (HY000): Error writing file ‘./mysql-bin.~rec~’ (Errcode: 28)
The PURGE BINARY LOGS command requires free space to be able to clear the logs, which is why this command was failing. To be able to run the command please to stop MySQL, zero the first binary log and also remove it from the mysql-bin.index file. Restart MySQL, run the command:
PURGE BINARY LOGS TO ‘BINLOG.000xxx’;
If you get this error
ERROR 1373 (HY000): Target log not found in binlog index
Check the date. Since the binary log was from September 4th, ran the following:
PURGE BINARY LOGS BEFORE ‘2014-09-04’;
Now the log files up to that date will be purged. If you are not using replication, you can most likely disable the binary logging unless you have this enabled for easier data recovery.