Sometimes you might notice that in /var/log/mysql there are many binlog files. In some circumstances, they could even end up filling your hard disk. If you experience this, in this article we will explain what those files are and what you can do in this situation.

Binlog files are created by MySQL in order to assist with point-in-time recovery or with duplication of databases. They are very handy to have when something goes wrong, but we have discovered that some WordPress plugins have the tendency to perform too many updates which end up being stored in the binlog files.

First of all, please confirm that this is the case by running the following commands:

sudo du -sh /var/log/mysql
sudo ll -l /var/log/mysql

If you see tens of binlog files, you probably have an extension or something that keeps updating your tables continuously.

The correct way to handle this situation is to purge those files from mysql. To do this use the following commands:

sudo su
mysql
mysql>> PURGE BINARY LOGS BEFORE '2019-04-02 22:46:26';

For obvious reasons you will want to set the date to something more meaningful! Running this command will clear the binlogs from your disk.

An additional step you can take is to alter the /etc/mysql/my.cnf file and to alter the following parameter:

expire_logs_days=1

This will ensure that you only keep one day worth of binary logs. Remember though that some plugins could fill up your disk in one day as well, so that best practice is to investigate which plugin is causing this in your case.

Did this answer your question?