一.更改 /etc/docker/daemon.json
sudo mkdir -p /etc/dockersudo tee /etc/docker/daemon.json <<-'EOF'
{"registry-mirrors": ["https://do.nark.eu.org","https://dc.j8.work","https://docker.m.daocloud.io","https://dockerproxy.com","https://docker.mirrors.ustc.edu.cn","https://docker.nju.edu.cn"]
}
EOF
sudo systemctl daemon-reload
sudo systemctl restart docker
二.拉取镜像
docker pull mysql:5.7
或者下载mysql5.7镜像(https://download.csdn.net/download/cyw8998/90187535),之后导入进来
docker load -i /home/mysql57.tar.gz
三.运行
docker run \
-p 3306:3306 \
--name mysql57 \
-v /home/mysql/log:/var/log/mysql \
-v /home/mysql/data:/var/lib/mysql \
-v /home/mysql/conf:/etc/mysql/conf.d \
--restart=always \
-e MYSQL_ROOT_PASSWORD=123456 \
-d mysql:5.7
四.宿主机/home/mysql/conf 下增加 my.cnf
# MySQL配置文件my.cnf
# 服务器标识
[mysqld]
# 设置服务器的默认字符集为utf8
character-set-server=utf8
# 客户端标识
[client]
# 设置客户端的默认字符集为utf8
default-character-set=utf8
五.重启
docker restart mysql57
或docker restart <containerid>