赞
踩
docker pull mysql:8.0.20
mkdir -vp /usr/local/docker/myMysql
cd /usr/local/docker/myMysql
mkdir data logs conf
docker run -d -p 3306:3306 --name mysql -e MYSQL_ROOT_PASSWORD=123456 mysql:8.0.20
#复制配置文件
docker cp mysql:/etc/mysql /usr/local/docker/myMysql/conf
#复制data文件
docker cp mysql:/var/lib/mysql /usr/local/docker/myMysql/data
docker stop mysql
docker rm -f mysql
docker run -d -p 3306:3306 \
--name mysql \
--privileged=true \
--restart=unless-stopped \
-v /usr/local/docker/myMysql/conf/mysql/conf.d:/etc/mysql/conf.d \
-v /usr/local/docker/myMysql/logs:/var/log/mysql \
-v /usr/local/docker/myMysql/data/mysql:/var/lib/mysql \
-e MYSQL_ROOT_PASSWORD=123456 \
mysql:8.0.20
#1、无法连接(不允许远程连接)
docker exec -it mysql /bin/bash
mysql -u root -p
use mysql
# 更新root - localhost 为 root - %
update user set host = '%' where user = 'root' and host='localhost';
# 设置允许远程用户访问
GRANT ALL ON *.* TO 'root'@'%';
flush privileges;# 刷新权限
#更新用户加密方式,mysql8默认的加密方式
ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY '密码';
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。