Resolving mysqldump '--set-gtid-purged=OFF' Issue in Debian Container with Homebrew

April 10, 2024

In this post, I will detail an issue encountered with mysqldump in a Debian environment and the resolution through the use of Homebrew. it was a tricky mysqldump issue in Debian where the --set-gtid-purged=OFF flag wasn't working and I couldn't find solutions online.

Everything was fine when you were testing the script on your local machine, but when you tried to run it in a Debian container, it failed. The issue was that the default MySQL client package in Debian didn't support the --set-gtid-purged=OFF option.

here was the initial Dockerfile snippet:

FROM debian:bookworm

RUN apt-get update && apt-get install -y default-mysql-client && rm -rf /var/lib/apt/lists/*

I built the image using this script (assuming the file name is 'Dockerfile_Bad'):

docker build --platform=linux/amd64 -f Dockerfile_Bad -t test_bad .

and then shell into the container:

docker run -it test_bad /bin/bash

and run the following command:

mysqldump --version


mysqldump  Ver 10.19 Distrib 10.11.6-MariaDB, for debian-linux-gnu (x86_64)

Clearly, the version mismatch was causing issues.

To get around this, I turned to Homebrew. It’s been a reliable fix for these kinds of package management problems, not just on macOS but for Linux as well. Here’s how I set it up in the Dockerfile to ensure everything would run smoothly:

FROM debian:bookworm

# Install necessary packages for Homebrew and mysqldump
RUN apt-get update && apt-get install -y curl build-essential file git sudo

# Create a non-root user for Homebrew installation
RUN useradd -m -s /bin/bash linuxbrew && \
    usermod -aG sudo linuxbrew && \
    echo 'linuxbrew ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers

# Switch to the non-root user
USER linuxbrew
WORKDIR /home/linuxbrew

# Install Homebrew
RUN /bin/bash -c "$(curl -fsSL"

# Set Homebrew environment variables
ENV PATH="/home/linuxbrew/.linuxbrew/bin:/home/linuxbrew/.linuxbrew/sbin:${PATH}"

# Install mysql-client via Homebrew
RUN brew install mysql-client

# Set environment variables based on Homebrew's post-installation message
ENV PATH="/home/linuxbrew/.linuxbrew/opt/mysql-client/bin:$PATH"
ENV LDFLAGS="-L/home/linuxbrew/.linuxbrew/opt/mysql-client/lib"
ENV CPPFLAGS="-I/home/linuxbrew/.linuxbrew/opt/mysql-client/include"
ENV PKG_CONFIG_PATH="/home/linuxbrew/.linuxbrew/opt/mysql-client/lib/pkgconfig"

# Switch back to root user for any further commands that require root access
USER root

which gives you this version of mysqldump:

mysqldump  Ver 8.3.0 for Linux on x86_64 (Homebrew)

The adoption of this method has proven effective, allowing for the successful operation of mysqldump with the --set-gtid-purged=OFF parameter in Debian. However, this solution will cause the image size to increase, so it's important to consider the trade-offs when implementing this fix.

© 2024 Kayhan Babaee. All Rights Reserved.