Purging mysql-bin files, a.k.a. saving GBs of SSD space

My SSD was filling up and while searching for the cause I ended at MySQL binary log files. They used almost 40GB :-O while I don’t use the logs so often and especially not so backdated

$ sudo ls -lSh /var/lib/mysql |head 
total 7.8G
-rw-rw---- 1 mysql mysql 1.1G May 18 13:34 mysql-bin.000521
-rw-rw---- 1 mysql mysql 796M May 14 20:36 mysql-bin.000517
-rw-rw---- 1 mysql mysql 528M May 21 20:18 mysql-bin.000525
-rw-rw---- 1 mysql mysql 370M May 22 20:18 mysql-bin.000526
-rw-rw---- 1 mysql mysql 367M May 17 19:44 mysql-bin.000520
-rw-rw---- 1 mysql mysql 354M May 13 20:38 mysql-bin.000516
-rw-rw---- 1 mysql mysql 348M May 2 20:25 mysql-bin.000503
-rw-rw---- 1 mysql mysql 297M May 18 20:13 mysql-bin.000522
-rw-rw---- 1 mysql mysql 285M May 16 20:29 mysql-bin.000519

After some googling I found how to purge the files.

PURGE BINARY LOGS BEFORE '2017-05-01 00:00:00';

Because I don’t want to be bothered with this same issue a set expire_log_days to the 60 days in my.cnf, because the default is 0, so no automatic removal.

Advertisements

Author: Michal Zuber

Full stack developer, biker and rollerblader. Owner and developer at https://nevilleweb.sk/ Co-founded http://neville.sk/ Blog at https://michalzuber.wordpress.com/

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s