mysql5.6.37官方docker镜像pull
- pull拉取镜像命令
docker pull mysql:5.6
dockerfile github地址https://github.com/docker-library/mysql/blob/7ee927986b8c0cbfa6cdbb073a0e662bdb62c18a/5.6/Dockerfile
-
检查下载的mysql:5.6镜像
docker images
docker images|findstr mysql
配置docker-compose.yml文件
version: '3'
services:
mysql5.6:
image: mysql:5.6
# restart: always
environment:
MYSQL_ROOT_PASSWORD: 123456
MYSQL_DATABASE: test
MYSQL_USER: test
MYSQL_PASSWORD: 123456
ports:
- 3306:3306
volumes:
- ./data/mysql:/var/lib/mysql
- ./conf/my.cnf:/etc/mysql/my.cnf
数据文件持久化和配置文件持久化时,在windows环境下,需要把磁盘共享给docker虚拟机
- 启动mysql
docker-compose up -d
- 检查数据是否持久化
- 常用命令
# 后台启动mysql :docker-compose up -d
# 进入mysql容器: docker-compose exec mysql5.6 bash
# 结束mysql容器:docker-compose down
# 停止mysql容器:docker-compose stop mysql5.6
# 重启mysql容器:docker-compose restart mysql5.6
- 备份数据库
docker-compose exec mysql5.6 bash
mysqldump --all-databases -uroot -p"$MYSQL_ROOT_PASSWORD"' > /home/backup/all-databases.sql```
- 回复数据库
docker-compose exec mysql5.6 bash
mysql -uroot -p"$MYSQL_ROOT_PASSWORD" < /home/backup/all-databases.sql```