docker

Docker安装Mysql 5.7并使用

2020-10-28  本文已影响0人  夹胡碰

1. 环境

2. 前置准备

参见: Linux Ceonto7安装Docker-CE并使用

3. 安装

3.1 创建挂载文件夹
mkdir -p /home/mysql-docker/conf
mkdir -p /home/mysql-docker/logs
mkdir -p /home/mysql-docker/mysql
3.2 安装
docker pull mysql:5.7
3.3 查看images镜像
[root@bogon docker]# docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
mysql               5.7                 1b12f2e9257b        5 days ago          448MB
3.4 启动Mysql5.7
docker run -d --privileged=true --name mysql -p 13306:3306 \
     -v /home/mysql-docker/conf:/etc/mysql/ \
     -v /home/mysql-docker/logs:/logs \
     -v /home/mysql-docker/mysql:/var/lib/mysql \
     -e MYSQL_ROOT_PASSWORD=root \
     mysql:5.7
3.5 查看启动状态
[root@bogon docker]# docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                                NAMES
f7726ecba2a2        mysql:5.7           "docker-entrypoint.s…"   14 seconds ago      Up 13 seconds       33060/tcp, 0.0.0.0:13306->3306/tcp   mysql
3.6 查看启动日志
docker logs f77
2020-10-28T03:05:34.756739Z 0 [Note] Plugin 'FEDERATED' is disabled.
2020-10-28T03:05:34.766346Z 0 [Note] InnoDB: Buffer pool(s) load completed at 201028  3:05:34
2020-10-28T03:05:34.770925Z 0 [Note] Found ca.pem, server-cert.pem and server-key.pem in data directory. Trying to enable SSL support using them.
2020-10-28T03:05:34.770963Z 0 [Note] Skipping generation of SSL certificates as certificate files are present in data directory.
2020-10-28T03:05:34.772922Z 0 [Warning] CA certificate ca.pem is self signed.
2020-10-28T03:05:34.773035Z 0 [Note] Skipping generation of RSA key pair as key files are present in data directory.
2020-10-28T03:05:34.774294Z 0 [Note] Server hostname (bind-address): '*'; port: 3306
2020-10-28T03:05:34.775517Z 0 [Note] IPv6 is available.
2020-10-28T03:05:34.775555Z 0 [Note]   - '::' resolves to '::';
2020-10-28T03:05:34.775614Z 0 [Note] Server socket created on IP: '::'.
2020-10-28T03:05:34.843091Z 0 [Note] Event Scheduler: Loaded 0 events
2020-10-28T03:05:34.843567Z 0 [Note] mysqld: ready for connections.
Version: '5.7.32'  socket: '/var/run/mysqld/mysqld.sock'  port: 3306  MySQL Community Server (GPL)

3.7 使用navcat连接

url: localhost:13306
用户名密码: root/root

连接成功


image.png
3.8 也可以使用命令行进入容器内,查看数据库
docker exec -it mysql /bin/bash
[root@bogon docker]# docker exec -it mysql /bin/bash
root@f7726ecba2a2:/# mysql -uroot -proot
mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
4 rows in set (0.00 sec)
上一篇 下一篇

猜你喜欢

热点阅读