How to Purge the BinLog for MySQL and MariaDB
If you see lots of disk space quickly disappearing on your MySQL or MariaDB server, then you may want to look into the BinLog
directory, it is located at /var/log/mysql/
.
In my case I saw this:
|
|
I looked to see how much space this was all taking:
Almost 5.5Gb
in this instance. I have seen servers go up into the many hundreds of Gigabytes before anyone notices.
I am not replicating logs to a cluster, or any slave nodes, so this is only taking up space, with no value add.
I can safely delete this, but how do I go about doing that?
How to safely purge Binary Logs
You can clear a specific log:
|
|
Or before a certain date:
|
|
Or before an exact time and date:
|
|
Make the Binary Logs go away forever
It’s also possible to remove the bin logs for good.
Open the /etc/mysql/my.cnf
file on the server and look for the section:
Now we can either comment these lines out and restart the MySQL/MariaDB server or adjust the values to expire quicker.
The commented out version looks like this:
Completely disable Binary Logs to disk
Within your /etc/mysql/my.cnf
file, you can add a line under the [mysqld]
section: