How to Disable Binlog in MySQL (Docker)

Server

Introduction

MySQL can generate numerous binlog files, which consume increasing amounts of disk space over time. This guide provides a solution to disable binlog in MySQL when using Docker.

Prerequisites

The environment used in this guide:

  • MySQL in Docker
  • MySQL version: image: mysql:8.4.0
  • Host: Raspberry Pi OS (Debian 12, Bookworm)
  • Docker Compose

Step-by-Step Instructions

To disable binlog, add the disable_log_bin option to the my.cnf file.

Step 1: Stop the MySQL Docker Container

sudo docker-compose down [container_name]

Step 2: Modify the my.cnf File

Add the disable_log_bin option to the [mysqld] section of my.cnf.

[mysqld]
disable_log_bin

Step 3: Remove All Binlog Files

sudo rm -rf /path/to/binlog/binlog*

Step 4: Restart the MySQL Docker Container

sudo docker-compose up [container_name] -d

Step 5: Check the Result

Execute the following command to verify that binlog is disabled:

docker exec -i <container name> sh -c 'exec mysql -uroot -p"$MYSQL_ROOT_PASSWORD" -e "SHOW GLOBAL VARIABLES LIKE \"log_bin\";"'

If the Value column shows OFF, the binlog has been successfully disabled:

Variable_name   Value
log_bin         OFF

Comments