Currently Available: Need a skilled Software Developer for your next project?
Categories
Docker Laravel

Fix Insane Disk I/O in Laravel Sail: Disable MySQL Binary Logs

Is your Docker-based development environment sluggish? Do your fans spin up for no reason? If you run docker stats, do you see your MySQL container writing gigabytes of data under the BLOCK I/O column?

If so, you've likely encountered the MySQL binary log (binlog). The binlog is a set of files that records every change made to your database. It's essential for replication and point-in-time recovery on production servers, but it's often a major performance killer in a local development environment.

For every INSERT, UPDATE, or DELETE your app performs, MySQL also performs a write operation to the binlog. On systems like WSL2, this constant I/O can bottleneck your entire machine.

The Symptom: Check Your Docker Stats

Run this command in your terminal while your application is running:

docker stats

Look for the BLOCK I/O column. If you see a massive write number for your mysql container, the binlog is the culprit.

CONTAINER ID   NAME               CPU %    MEM USAGE / LIMIT   BLOCK I/O
0251fff5e872   my-project-mysql-1 2.23%    684.5MiB / 31.2GiB  133MB / 13.3GB  <-- Problem!

The Solution: A One-Line Fix

You can disable the binary log by adding a single startup command to your docker-compose.yml file.

  1. Stop your environment:
    sail down
  2. Edit docker-compose.yml:
    Find the service definition for mysql and add the command: --disable-log-bin line.

    # docker-compose.yml
    
    services:
        # ... other services
        mysql:
            image: 'mysql/mysql-server:8.0'
    +       command: --disable-log-bin
            ports:
                - '${FORWARD_DB_PORT:-3306}:3306'
            environment:
    # ... rest of the file

The Cleanup: Reclaim Your Disk Space

After applying the fix, the old, multi-gigabyte log files will still exist inside your Docker volume. You have two options to clean them up.

Option A: The Fresh Start (Deletes Database)

This is the easiest method. It destroys the MySQL volume, deleting the old logs and all of your data.

# This will completely WIPE your development database
sail down -v

# Start fresh and migrate
sail up -d
sail artisan migrate --seed

Option B: The Pro Move (Keeps Your Data)

If you have custom data you don't want to lose, you can log into the container and surgically remove just the binlog files.

  1. Start your containers: sail up -d
  2. Get a shell inside the MySQL container: sail exec mysql bash
  3. Log in to the MySQL client: mysql -u root -p (Use your DB_PASSWORD)
  4. Run the master reset command. This is safe and only deletes the binlogs:
    RESET MASTER;
What I'm building

Delegate tasks. Get software.

Give Vroni a GitHub issue, bug report, spec, or rough idea. It reads the repo, plans the change, writes code, runs checks, and works toward a review-ready pull request.

Take a look at vroni.com

Subscribe to my newsletter

Get new posts when I publish them.

I respect your privacy. Unsubscribe at any time.

Leave a Reply

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