Databases 7 min read

How to Disable MySQL Binary Logging to Free Disk Space

The article explains why excessive MySQL binary logs filled a CentOS server’s disk, walks through cleaning unrelated logs, shows how to inspect and purge the binlog files, and provides the exact my.cnf changes needed to permanently disable binary logging.

21CTO
21CTO
21CTO
How to Disable MySQL Binary Logging to Free Disk Space

While developing a Laravel application that performs many temporary writes, the author’s test server on CentOS Stream ran out of disk space because MySQL’s binary logs grew to over 15 GB.

Clean unrelated large files

# find /var -name "*.log" ( ( -size +50M -mtime +7 ) -o -mtime +30 ) -exec truncate {} --size 0 ;
# yum clean all
# rm -rf /var/tmp/yum-*
# package-cleanup --quiet --leaves | xargs yum remove -y
# rm -rf /root/.wp-cli/cache/*
# rm -rf /home/*/.wp-cli/cache/*
# (( $(rpm -E %{rhel}) >= 8 )) && dnf remove $(dnf repoquery --installonly --latest-limit=-2 -q)
# (( $(rpm -E %{rhel}) <= 7 )) && package-cleanup --oldkernels --count=2
# rm -rf /root/.composer/cache
# rm -rf /home/*/.composer/cache
# find -regex ".*/core\.[0-9]+$" -delete
# find /home/*/public_html/ -name error_log -delete
# rm -rf /root/.npm /home/*/.npm /root/.node-gyp /home/*/.node-gyp /tmp/npm-*
# rm -rf /var/cache/mock/* /var/lib/mock/*
# rm -rf /home/*/.cache/*/* /root/.cache/*/*

After these clean‑ups the disk usage improvement was minimal, so the author inspected the MySQL data directory:

du -h / -d 1

The command showed that /var/lib/mysql/ occupied more than 15 GB, with individual binary log files such as binlog.000001 (503 B) up to binlog.000010 (≈1 GB each).

MySQL’s default installation enables binary logging to track changes for replication. In the author’s environment there is only a primary instance, so the logs serve no purpose and consume disk space.

Reset or purge existing binary logs

Log in as root to the MySQL console:

mysql -uroot -p

To delete all binary logs:

RESET MASTER;

To delete only older logs (e.g., older than two days):

PURGE BINARY LOGS BEFORE DATE(NOW() - INTERVAL 2 DAY) + INTERVAL 0 SECOND;

Disable binary logging permanently

Edit the MySQL configuration file and add a line that turns off logging:

sudo vim /etc/mysql/my.cnf
disable-log-bin   # disables binary logging completely
# Optional limits if you still want logs for a short period
# expire_logs_days = 3
# max_binlog_size = 500M

After saving the file, restart MySQL:

sudo service mysqld restart

Warning

If the disable-log-bin line is added before the existing logs are cleared, commands such as RESET MASTER will be ignored and PURGE BINARY LOGS will have no effect. Therefore, clear the logs first, then add the configuration and restart.

Better long‑term solution

The immediate fix solved the disk‑space issue, but the author notes that writing large temporary or binary data to MySQL is not ideal; a different storage solution should be considered for such data.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

ConfigurationMySQLCentOSdisk spaceLaravelbinary logging
21CTO
Written by

21CTO

21CTO (21CTO.com) offers developers community, training, and services, making it your go‑to learning and service platform.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.