MySQL 8 Binary Logs

MySQL 8 binary logs can grow unwilling and cause database is out of disk space.

I’ve been dealing with some issues on my server which is hosted at Linode, and managed by ServerPilot. After doing some cleanup in late 2023, things have been running smoothly. But earlier this year I started getting database connection issues due to limited storage space left.

I did some data cleanup a couple of times, but ran into the issue more and more. Since I had the server instance since ~2017, and had updated it from Ubuntu 16 to 18, then 20, and finally 22. Maybe some extra crap was left behind. Earlier this month I released a new plugin the monitor your WordPress sites health. For more information you can checkout the blog post where I use n8n to run a daily health check.

One final step I wanted to perform was upgrading my server from a Linode 2 GB, to a Linode 4 GB server which bumps the storage from 50 GB too 80 GB (plus some other goodies like more RAM and CPUs). With this complete, and my n8n automation I thought I was in the clear.

Health Check: ALERT

Over Fathers Day weekend, I took a couple extra days off without my computer so we could enjoy northern California. Well, the day after Fathers Day at 9 PM, I got a Slack alert that said the health check failed. I looked, and all the apps on the server were offline. So at least I know the automation and health check work.

Once I got home, I dug deeper into the issues, and finally found this article that helped point me into the right direction, and this Ask Ubuntu thread. Once I ran the following command du -cha --max-depth=1 /var/lib/mysql | grep -E "G" I saw massive amounts of MySQL Binary Log files that added up to over 54 GB!

Binary Log Cleanup

Once I logged into my server via SSH as root, and went into mysql CLI and ran the following:

SHOW BINARY LOGS;
PURGE BINARY LOGS BEFORE DATE(NOW() - INTERVAL 3 DAY);
SHOW BINARY LOGS;

Then ran:

SET GLOBAL binlog_expire_logs_seconds = 259200;
SET PERSIST binlog_expire_logs_seconds = 259200;

Purging the logs cleared 54 GB of storage, and now I am happy.

Austin
Austin

πŸ’πŸ½β€β™‚οΈ Husband to Jeana.
⚾️ Dodgers & Brewers.
πŸ’» PHP Engineer.
πŸŒπŸΌβ€β™‚οΈGolfer; ~15 HDC.
🌱 Hydroponic Gardner.
🍿 Plex nerd.
πŸš™ '15 WRX, '22 Model 3 LR, & '66 Corvette C2.

Follow me on X @TheFrosty & Instagram @TheFrosty.

Articles: 296

Leave a Reply

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