day 02-dockerインストールMySQL 8


環境:時間:2018年12月2日システム:centos 7
リソースの取得
[root@wg001 ~]# docker pull mysql:8.0


新規コンテナ
[root@wg001 ~]# docker run --name gaomysql -p 3306:3306 -e MYSQL_ROOT_PASSWORD=MySQL118118! -d mysql
Unable to find image 'mysql:latest' locally
latest: Pulling from library/mysql
Digest: sha256:b7f7479f0a2e7a3f4ce008329572f3497075dc000d8b89bac3134b0fb0288de8
Status: Downloaded newer image for mysql:latest
79d5e57e343e0d517874c5c7e3643c1f19dc95059b4c5d49f70155f6162d9981


実行中のコンテナの表示
[root@wg001 ~]# docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                               NAMES
79d5e57e343e        mysql               "docker-entrypoint.s…"   40 seconds ago      Up 38 seconds       0.0.0.0:3306->3306/tcp, 33060/tcp   gaomysql
[root@wg001 ~]# 


MySQLへ
[root@wg001 ~]# docker exec -it gaomysql /bin/bash
root@79d5e57e343e:/# 


コマンドを直接使用してデータベースにログイン
root@79d5e57e343e:/# mysql -uroot -pMySQL118118!
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 8
Server version: 8.0.13 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> 


リモートツールでの接続を確実に行うには、次のように設定します.
mysql> use mysql
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY 'root';
Query OK, 0 rows affected (0.01 sec)

mysql> alter user 'root'@'%' identified by '123456';
Query OK, 0 rows affected (0.10 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

mysql> 


コンテナを終了し、コンテナがctrl+P+Qを実行することを保証する
リモートログインテスト
[root@wg001 ~]# mysql -uroot -p123456 -h 172.17.0.1
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MySQL connection id is 9
Server version: 8.0.13 MySQL Community Server - GPL

Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MySQL [(none)]> 


コンテナipの表示
#docker ps

コンテナIDによるipの表示
[root@wg001 ~]# docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                               NAMES
79d5e57e343e        mysql               "docker-entrypoint.s…"   9 minutes ago       Up 9 minutes        0.0.0.0:3306->3306/tcp, 33060/tcp   gaomysql
[root@wg001 ~]# 

[root@wg001 ~]# docker inspect 79d5e