Introduction:
This guide explains how to reduce disk usage caused by mysql-bin log files in /var/lib/mysql.
Binary logs store database changes and can grow quickly on active servers, filling disk space.
By configuring log expiration, old logs will be automatically removed.
Prerequisites:
- Root or sudo access
- SSH access to the server
- MySQL/MariaDB running
Step 1:
Log in to the server or access the terminal via WHM.
| $ ssh root@your-server-ip |
Step 2:
Open the MySQL configuration file and edit it.
| $ vi /etc/my.cnf |
Add the following line under the [mysqld] section:
| binlog_expire_logs_seconds = 86400 |
Explanation
86400= 1 day- This means logs older than 1 day will be automatically deleted
You can adjust as needed:
- 604800 → 7 days
- 2592000 → 30 days
Step 3:
Restart the MySQL service.
| $ systemctl restart mysqld |
Conclusion
By applying this configuration:
1. Old mysql-bin files will be automatically removed
2. Disk usage will be controlled
3. Future disk space issues will be prevented