1

We've had some problems with one of our more elderly MySQL servers (version 5.045). The database is back up and running OK but there were over twenty thousand binary log files in the mysql folder.

I logged into MySQL and issued the following command after checking that data replication was all working OK...

purge binary logs to 'mysql-bin.024717';

The command completed without error and the resulting mysql-bin.index looks like this...

./mysql-bin.024717
./mysql-bin.024718
./mysql-bin.024719
./mysql-bin.024720
./mysql-bin.024721
./mysql-bin.024722
./mysql-bin.024723
./mysql-bin.024724

When I left mysql a lot of files had gone, but now there are still over a thousand binary log files left, all from before mysql-bin.024717 and most of them only containing 117 bytes.

Given that they are no longer referenced in the mysql-bin.index file is it OK for me to just go ahead and remove them with rm at the OS level or do I need to do something else to clean them up?

Thanks in Advance

1

You can also try purge binary logs before '2016-04-29 08:00:00'. I sometimes find one works when the other doesn't for some reason.

Failing that just delete them with rm like you said. It's not technically correct, but it shouldn't be a problem (I did this frequently in the past before I learned about the PURGE commands, and never had any problems).

Of course you also want to make sure you have expire_logs_days set as well to keep them down in future.

I also just saw this note:

Prior to MySQL 5.1.24, PURGE BINARY LOGS TO and PURGE BINARY LOGS BEFORE did not behave in the same way (and neither one behaved correctly) when binary log files listed in the .index file had been removed

for some reason I don't have access to the 5.0 page to check what that says.

0

(Follow-on to @IGGt)

"Prior to MySQL 5.0.60, PURGE BINARY LOGS TO and PURGE BINARY LOGS BEFORE did not behave in the same way (and neither one behaved correctly) when binary log files listed in the .index file had been removed from the system by some other means (such as using rm on Linux). Beginning with MySQL 5.0.60, both variants of the statement fail with an error in such cases. (Bug #18199, Bug #18453) To handle such errors, edit the .index file (which is a simple text file) manually to ensure that it lists only the binary log files that are actually present, then run again the PURGE BINARY LOGS statement that failed." -- http://dev.mysql.com/doc/refman/5.0/en/purge-binary-logs.html

PURGE BINARY LOGS was added in 4.1 or 5.0, I don't remember which.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.