ubuntu/mysql

Verified Publisher

By Canonical

Updated 6 months ago

MySQL open source fast, stable, multi-thread SQL database. Long-term tracks maintained by Canonical.

Image
Databases & Storage

500K+

MySQL™ software | Ubuntu

Current MySQL™ software Docker Image from Canonical, based on Ubuntu. Receives security updates and rolls to newer MySQL™ software or Ubuntu release. This repository is free to use and exempted from per-user rate limits.

About MySQL™ software

MySQL is a fast, stable and true multi-user, multi-threaded SQL database server. SQL (Structured Query Language) is the most popular database query language in the world. The main goals of MySQL are speed, robustness and ease of use. Read more on the MySQL website.

Tags and Architectures

LTS Up to 5 years of free security maintenance on LTS channels.

ESM Up to 10 years of customer security maintenance from Canonical's restricted repositories.

Channel TagsSupported untilCurrentlyArchitectures
8.0-22.04_beta04/2027MySQL™ software 8.0 on Ubuntu 22.04 LTSamd64, arm64, ppc64el, s390x
8.0-20.04_beta04/2025MySQL™ software 8.0.39 on Ubuntu 20.04 LTSamd64, arm64, ppc64el, s390x
track_risk

Channel Tags shows the most stable channel for that track ordered stable, candidate, beta, edge. More risky channels are always implicitly available. So if beta is listed, you can also pull edge. If candidate is listed, you can pull beta and edge. When stable is listed, all four are available. Images are guaranteed to progress through the sequence edge, beta, candidate before stable.

Commercial use and Extended Security Maintenance channels

If your usage includes commercial redistribution, or requires ESM or unavailable channels/versions, please get in touch with the Canonical team (or using rocks@canonical.com).

Usage

Launch this image locally:

docker run -d --name mysql-container -e TZ=UTC -p 30306:3306 -e MYSQL_ROOT_PASSWORD=My:S3cr3t/ ubuntu/mysql:8.0-22.04_beta

Access your MySQL server at localhost:30306.

Parameters

ParameterDescription
-e TZ=UTCTimezone.
-e MYSQL_ROOT_PASSWORD=secret_for_rootSet the password for the root user. This option is mandatory and must not be empty.
-e MYSQL_PASSWORD=secretSet the password for the MYSQL_USER user.
-e MYSQL_USER=johnCreate a new user with superuser privileges. This is used in conjunction with MYSQL_PASSWORD.
-e MYSQL_DATABASE=db_testSet the name of the default database.
-e MYSQL_ALLOW_EMPTY_PASSWORD=yesSet up a blank password for the root user. This is not recommended to be used in production, make sure you know what you are doing.
-e MYSQL_RANDOM_ROOT_PASSWORD=yesGenerate a random initial password for the root user using pwgen. It will be printed in the logs, search for GENERATED ROOT PASSWORD.
-e MYSQL_ONETIME_PASSWORD=yesSet root user as experide once initialization is complete, forcing a password change on first login.
-e MYSQL_INITSB_SKIP_TZINFO=yesTimezone data is automatically loaded via entrypoint script, set this variable to any non-empty value to disable it.
-p 30306:3306Expose MySQL server on localhost:30306.
-v /path/to/data:/var/lib/mysqlPersist data instead of initializing a new database every time you launch a new container.
-v /path/to/config/files/:/etc/mysql/mysql.conf.d/Local configuration files (try this example my.cnf).

Initialization Scripts

One can also add initialization scripts to their containers. This includes *.sql, .sql.gz, and *.sh scripts, and you just need to put them inside the /docker-entrypoint-initdb.d directory inside the container. After MySQL initialization is done and the default database and user are created, the scripts are executed in the following order:

  • Run any *.sql files in alphabetically order. By default the target database is specified via MYSQL_DATABASE.
  • Run any executable *.sh scripts in alphabetically order.
  • Source any non-executable *.sh scripts in alphabetically order.

All of this is done before the MySQL service is started. Keep in mind if your database directory is not empty (contains pre-existing database) they will be left untouched.

Testing/Debugging

To debug the container:

docker logs -f mysql-container

To get an interactive shell:

docker exec -it mysql-container /bin/bash

This image also includes the mysql client for interactive container use:

$ docker network create mysql-network
$ docker network connect mysql-network mysql-container
$ docker run -it --rm --network mysql-network ubuntu/mysql:8.0-22.04_beta mysql -hmysql-container -uroot -p

The password will be asked and you can enter My:S3cr3t/. Now, you are logged in and can enjoy your new instance.

Deploy with Kubernetes

Works with any Kubernetes; if you don't have one, we recommend you install MicroK8s and microk8s.enable dns storage then snap alias microk8s.kubectl kubectl.

Download my-custom.cnf and mysql-deployment.yml and set containers.mysql.image in mysql-deployment.yml to your chosen channel tag (e.g. ubuntu/mysql:8.0-22.04_beta), then:

kubectl create configmap mysql-config --from-file=main-config=my-custom.cnf
kubectl apply -f mysql-deployment.yml

You will now be able to connect to the MySQL server on localhost:30306.

Bugs and feature requests

If you find a bug in our image or want to request a specific feature, please file a bug here:

https://bugs.launchpad.net/ubuntu-docker-images/+filebug

Please title the bug "mysql: <issue summary>". Make sure to include the digest of the image you are using, from:

docker images --no-trunc --quiet ubuntu/mysql:<tag>

Deprecated channels & tags

These channels (tags) are not updated anymore. Please upgrade to newer channels, or reach out if you can't upgrade.

TrackVersionEOLUpgrade Path
8.0-21.10MySQL™ software 8.0.27 on Ubuntu 21.10 07/2022 8.0-22.04_beta
8.0-21.04MySQL™ software 8.0.27 on Ubuntu 21.04 01/20228.0-21.10
track

Docker Pull Command

docker pull ubuntu/mysql