Limit disk used by MySQL binary log files
On a server, the disk was almost full. On checking most of the disk space is used in “/var/lib/mysql” folder, which had many MySQL binary logs.
In the MySQL command prompt, run the command to see all MySQL binary logs
1 |
SHOW BINARY LOGS; |
On checking MySQL configuration, I had the line
1 |
max_binlog_size = 100M |
This limited the binlog file size to 100 MB, when the file size reached 100 MB, the file get rotated.
How long logs are kept is determined by the value of binlog_expire_logs_seconds. The default value for this variable was 2592000, which is approx 30 days.
To make the MySQL bin log expire after 48 hours, add the following to the MySQL configuration file under the [mysqld] directive.
1 2 |
[mysqld] binlog_expire_logs_seconds=86400 |
Restart the MySQL server with
1 |
systemctl restart mysql |
On RHEL based servers
1 |
systemctl restart mysqld |
After restarting I checked the disk space used by folder “/var/lib/mysql”, it changed to 13 GB, which is much lower than the initial MySQL disk usage.
Back to MySQL