Massive amounts of disk space consumed by MySQL and Mariadb binlog files

Background

You might find on a MySQL 8.x or MariaDB 10.4 server that suddenly disk space just evaporates.

After using ncdu you see the problem occurs in /var/lib/mysql and there you notice numerous 101M files “binlog.xxxxxx”.

Apparently this change was brought in MySQL 8.0:

> Binary logs can be used for auditing purposes, rebuilding databases to a point in time, examining scope of an update/delete, and things like that.

Fix the problem:

mysql> PURGE BINARY LOGS BEFORE '2023-06-13 00:00:00';
Query OK, 0 rows affected (4.21 sec)

Make it expire every 3 days (this only works on MySQL):

mysql> SET GLOBAL binlog_expire_logs_seconds = 259200;
Query OK, 0 rows affected (0.01 sec)

mysql> SET PERSIST binlog_expire_logs_seconds = 259200;
Query OK, 0 rows affected (0.02 sec)

Reference

Share this article

Leave a Reply

Your email address will not be published. Required fields are marked *

Scroll to Top