DEV Community

Aashutosh Poudel
Aashutosh Poudel

Posted on

Cleanup large binary logs in MySQL

I had an issue where my drive was almost occupied by mysql log files (almost 400G). I am not sure about the cause of the issue but I needed a way to remove those files fast. This was in my local dev machine so I decided to remove those files completely.

Here's a few commands to help you purge those files.

To purge logs created until a specific date:
mysql> PURGE BINARY LOGS BEFORE '2022-11-25 00:00:00';

To expire logs after certain time:
mysql> SET GLOBAL binlog_expire_logs_seconds=86400;

Additionally, set binlog_expire_logs_seconds in a config file to persist it between service restarts.

References:

  1. How to Solve Increasing Size of MySQL Binlog Files Problem?
  2. binlog_expire_logs_seconds docs

Top comments (0)