环境:
 时间: 2018年12月2日
 系统: centos7
获取资源
[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                










