MySQL Docker

Start

docker run --name mymysql1 -e MYSQL_ROOT_PASSWORD=myroot1 -d mysql:latest

Where mymysql1 is the name you want to assign to the container, myroot1 is the password to be set for the MySQL root user and latest is a tag indicating you want the latest version of MySQL. Using other tags allows you to install specifc versions. See https://hub.docker.com/_/mysql/ for full list.

docker container ls

CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMESc20bbc5890a7 mysql:latest "docker-entrypoint.s…" About an hour ago Up About an hour 3306/tcp, 33060/tcp mymysql1

Test

docker exec -it mymysql1 bash

mysql -u root -p

Enter the root password you provided during the initial "docker run" above

\s

--------------mysql Ver 8.0.30 for Linux on x86_64 (MySQL Community Server - GPL)
Connection id: 8Current database: Current user: root@localhostSSL: Not in useCurrent pager: stdoutUsing outfile: ''Using delimiter: ;Server version: 8.0.30 MySQL Community Server - GPLProtocol version: 10Connection: Localhost via UNIX socketServer characterset: utf8mb4Db characterset: utf8mb4Client characterset: latin1Conn. characterset: latin1UNIX socket: /var/run/mysqld/mysqld.sockBinary data as: HexadecimalUptime: 8 min 30 sec
Threads: 2 Questions: 5 Slow queries: 0 Opens: 119 Flush tables: 3 Open tables: 38 Queries per second avg: 0.009--------------

To see the MySQL Log use...

docker logs mymysql1

Bibliography