MySql教程

Docker安装MySQL

本文主要是介绍Docker安装MySQL,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

此处拿mysql5.7作为示范

1.安装mysql5.7镜像

docker pull mysql:5.7
5.7: Pulling from library/mysql
f003217c5aae: Already exists
65d94f01a09f: Already exists
43d78aaa6078: Already exists
a0f91ffbdf69: Already exists
59ee9e07e12f: Already exists
04d82978082c: Already exists
70f46ebb971a: Already exists
ba61822c65c2: Pull complete
dec59acdf78a: Pull complete
0a05235a6981: Pull complete
c87d621d6916: Pull complete
Digest: sha256:1a73b6a8f507639a8f91ed01ace28965f4f74bb62a9d9b9e7378d5f07fab79dc
Status: Downloaded newer image for mysql:5.7
docker.io/library/mysql:5.7

2. 启动mysql容器

docker run -d -p 3306:3306 -v E:\dockerWorkspace\mysql5.7\conf:/etc/mysql/conf.d  -v E:\dockerWorkspace\mysql5.7\data:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=root --name mysql57  mysql:5.7

# 参数解析
-d 后台运行
-v 挂载卷 主机目录:容器目录 可挂载多个卷
-e 设置参数 此处设置MYSQL初始密码
--name 设置容器名称

3. 检测是否启动成功

docker ps


CONTAINER ID   IMAGE       COMMAND                  CREATED         STATUS         PORTS                               NAMES
340468efcecf   mysql:5.7   "docker-entrypoint.s…"   5 minutes ago   Up 5 minutes   0.0.0.0:3306->3306/tcp, 33060/tcp   mysql57

这篇关于Docker安装MySQL的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!