Last Updated: February 25, 2016
·
975
· boris

Clean mysql binary logs

I've a ~700MB database with about 357G of binary logs. That's a lot! Looking into my database's configuration, I found following:

mysql> show variables like '%expire%';
+------------------+-------+
| Variable_name    | Value |
+------------------+-------+
| expire_logs_days | 15    |
+------------------+-------+
1 row in set (0.00 sec)

Do I really need 15 days of binary logs? In this case, no. How to fix it? There are two options. One is do it on the fly and the other is adding some parameter to MySQL config file. I did both of them, because I didn't want to restart/reload my MySQL service:

mysql> set global expire_logs_days=1;
Query OK, 0 rows affected (0.00 sec)

mysql> show variables like '%expire%';
+------------------+-------+
| Variable_name    | Value |
+------------------+-------+
| expire_logs_days | 1     |
+------------------+-------+
1 row in set (0.00 sec)

This will keep only one day of history of my binary log. The only problem here is that the variable is not persistent so after any service restart it will go back to 15. To make it persistent, I added following line to my my.cnf file:

expire_logs_days = 1

Enjoy and share :)