A MySQL Server installation with Docker at https://hub.docker.com/r/mysql/mysql-server/
There exists 2 mysql docker images
Run it and forward the port
docker run \
--name mysql \
-p 3306:3306 \
-e MYSQL_ROOT_PASSWORD=secret \
-e MYSQL_ROOT_HOST=% \
-v /my/conf:/etc/mysql/conf.d
-d \
mysql/mysql-server
docker run ^
--name mysql ^
-p 3306:3306 ^
-e MYSQL_ROOT_PASSWORD=secret ^
-e MYSQL_ROOT_HOST=% ^
-d ^
mysql/mysql-server
where the user configuration are:
You can change the configuration:
docker run \
--name mysql \
-p 6603:3306 \
-e MYSQL_ROOT_PASSWORD=secret \
-e MYSQL_ROOT_HOST=% \
-v /my/conf:/etc/mysql/conf.d \ # for the mysql image
-v /my/conf/my.cnf:/etc/my.cnf \ # for the mysql-server image
-d \
mysql/mysql-server
docker run --name some-mysql -e MYSQL_ROOT_PASSWORD=my-secret-pw -d mysql:tag --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci
# all conf can be seen with
docker run -it --rm mysql:latest --verbose --help
The docker image will execute files with extensions .sh, .sql and .sql.gz that are found in /docker-entrypoint-initdb.d in alphabetical order.
In a lot of docker image, the sql scripts found in the /docker-entrypoint-initdb.d/ folder.
You can populate mysql services by mounting a SQL dump into that directory
SQL files will be imported by default to the database specified by the MYSQL_DATABASE variable.
example: debezium/docker-images/tree/master/examples/mysql/0.7
docker run --name some-mysql \
-v /my/own/datadir:/var/lib/mysql \
-e MYSQL_ROOT_PASSWORD=my-secret-pw \
-d \
mysql:tag
where:
docker logs mysql-server
[Entrypoint] MySQL Docker Image 5.7.19-1.1.0
[Entrypoint] Initializing database
[Entrypoint] Database initialized
Warning: Unable to load '/usr/share/zoneinfo/iso3166.tab' as time zone. Skipping it.
Warning: Unable to load '/usr/share/zoneinfo/zone.tab' as time zone. Skipping it.
Warning: Unable to load '/usr/share/zoneinfo/zone1970.tab' as time zone. Skipping it.
[Entrypoint] ignoring /docker-entrypoint-initdb.d/*
[Entrypoint] Server shut down
[Entrypoint] MySQL init process done. Ready for start up.
[Entrypoint] Starting MySQL 5.7.19-1.1.0
With docker, you can connect with the mysql cli:
docker exec -it mysql-server mysql -uroot -psecret
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 492
Server version: 5.7.19 MySQL Community Server (GPL)
Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
With MySQLWorkbench or Dbeaver, you can connect with the following value:
Dbeaver: allowPublicKeyRetrieval=true
When checking the logs, you may get an Access denied
docker logs mysql-name
[Entrypoint] MySQL Docker Image 5.7.19-1.1.0
[Entrypoint] Initializing database
[Entrypoint] Database initialized
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
Their is a bug when you try to create the database. Suppress the parameter MYSQL_DATABASE, MYSQL_USER, MYSQL_PWD and create it yourself.
Add the parameter MYSQL_ROOT_HOST to your docker run command. See create_a_container_and_start_it. The value:
With DBeaver, you need to set the property allow public key retrieval