MySQL8.0 on Docker

# 最新版もってくる
# https://dev.mysql.com/doc/relnotes/mysql/8.0/en/
$ docker pull mysql:8.0.4

# 確認
$ docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
mysql               8.0.4               96dd4fed4359        6 weeks ago         291MB

# 起動
$ docker run --name mysql8 -e MYSQL_ROOT_PASSWORD=wak9wa9 -d --rm mysql:8.0.4

# 確認
$ docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS               NAMES
da8a09c01b01        mysql:8.0.4         "docker-entrypoint.s…"   2 seconds ago       Up 10 seconds       3306/tcp            mysql8

# 接続
$ docker exec -it mysql8 mysql -uroot -pwa9wa9
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 11
Server version: 8.0.4-rc-log MySQL Community Server (GPL)

Copyright (c) 2000, 2018, 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> select version() as mysql_version;
+---------------+
| mysql_version |
+---------------+
| 8.0.4-rc-log  |
+---------------+
1 row in set (0.00 sec)

# MySQL クライアントがなくてもこれでイケる
$ docker run -it -v $HOME/tmp/mysql8/:/var/host --link mysql8:mysql --rm mysql:8.0.4 sh -c 'exec mysql -h mysql -uroot -pwa9wa9 -P3306'

-v オプションがミソっぽい (docker で立ち上げたコンテナの上に、ホストのソースコードをバインドマウントする)

これで 違うconf 読み込むとかもできる

# カスタム conf
$ cat /tmp/custom.cnf
[mysqld]
default_authentication_plugin= mysql_native_password

# conf 指定、port 変更
$ docker run -v $HOME/tmp/:/etc/mysql/conf.d --name mysql8 -e MYSQL_ROOT_PASSWORD=wa9wa9 -d -p 13306:3306 --rm mysql:8.0.4

# これで localhost の MySQLクライアントからも接続できる
$ mysql -u root -p -h 127.0.0.1 -P 13306

REF