Mysql – How to prevent MySQL from filling up the disc with binary log files

MySQL

I have the following settings in my /etc/my.cnf

log-bin                 = /var/lib/mysql_bin_logs/mysql-bin.log
expire_logs_days        = 3
max_binlog_size         = 100M
relay-log               = /var/lib/mysql/slave-relay.log
relay-log-index         = /var/lib/mysql/slave-relay-log.index
log-slave-updates

and I can see that the /var/lib/mysql_bin_logs/ folder remains at a constant size. However the disc is filling up and I think it is to do with the file descriptor's for these binary log file not being closed properly. When I restart MySQL, disk usage drops by several Gigabytes, suggesting that act of restarting is freeing up the space.

How do I prevent the disk being filled up this way other than restarting MySQL on a cronjob?

Best Answer

First I'd try lsof -u mysql while it's running to see what files MySQL has open. You may also find it more helpful to do lsof -u mysql | grep deleted to see files that MySQL still has open but are deleted. If it turns out to be the log files hanging around you could try issuing a FLUSH LOGS inside MySQL as a workaround and see if it closes them.

Related Topic