'Install mysql client in docker image

I am trying to build a docker image for php, which can handle database dumping in my mysql container. The problem is that it seems to install the mariadb version instead of the mysql version of the client. This gives me an error mysqldump: unknown variable 'set-gtid-purged=OFF'

The script that does the dumping is not one I can change, as it is part of the laravel core. It detects the server sql version to see if it should add that command or not. So I really need to have the right client version on my php image/container.

This is my Dockerfile

FROM library/php:7.4-fpm

RUN apt-get update \
    && apt-get install -y default-mysql-client


Solution 1:[1]

I managed to find a solution. I decided to read through how the official mysql image is built, and implement the same solution here.

https://hub.docker.com/layers/mysql/library/mysql/latest/images/sha256-b589f11ab39a852fd13090aeb56314978c73a16d615e28ec148306889b67889f?context=explore

So adding in this, installed the needed client and everything works.

RUN apt-key adv --keyserver ha.pool.sks-keyservers.net --recv-keys 8C718D3B5072E1F5

RUN echo "deb http://repo.mysql.com/apt/debian/ buster mysql-8.0" > /etc/apt/sources.list.d/mysql.list

RUN apt-get update \
    && apt-get install -y mysql-community-client

Solution 2:[2]

If you build that image then run docker run -it <MyImageName> bash you can kinda explore what is going on.

apt show default-mysql-client shows the following so you are correct it is mariadb.

root@ff27370412ab:/var/www/html# apt show default-mysql-client
Package: default-mysql-client
Version: 1.0.5
Priority: optional
Section: database
Source: mysql-defaults
Maintainer: Debian MySQL Maintainers <[email protected]>
Installed-Size: 10.2 kB
Depends: mariadb-client-10.3
Download-Size: 3532 B
APT-Manual-Installed: yes
APT-Sources: http://deb.debian.org/debian buster/main amd64 Packages
Description: MySQL database client binaries (metapackage)

You can then run apt search mysql to find other packages you can use.

I glanced through a few of them but didn't find any that seemed like non maraidb. But you can add it to your apt repo using the following steps. https://dev.mysql.com/doc/mysql-apt-repo-quick-guide/en/

Solution 3:[3]

As stated by @jeff-h above, the answer has slightly changed since November 2021:

RUN set -ex; \
# gpg: key 5072E1F5: public key "MySQL Release Engineering <[email protected]>" imported
    key='859BE8D7C586F538430B19C2467B942D3A79BD29'; \
    export GNUPGHOME="$(mktemp -d)"; \
    gpg --batch --keyserver keyserver.ubuntu.com --recv-keys "$key"; \
    gpg --batch --export "$key" > /etc/apt/trusted.gpg.d/mysql.gpg; \
    gpgconf --kill all; \
    rm -rf "$GNUPGHOME"; \
    apt-key list > /dev/null

The key difference here (pun intended) is the new keyserver address.

  • Old: ha.pool.sks-keyservers.net
  • New: keyserver.ubuntu.com

Edit; Added the new key from @jeff-h's comment below.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Sinnbeck
Solution 2 Spasnof
Solution 3