1.查看 mysql 所有版本
docker search mysql
docker-tags mysql
docker-tag 命令参照 docker查看镜像tag(版本)
2.拉取 MySQL 镜像
docker pull mysql:5.7.5
3.拷贝容器内 mysql 默认配置文件到指定目录中
docker images
mkdir -p /usr/local/src/dockercontain/mysql/data
docker run -itd --name mysql-test -p 3306:3306 -e MYSQL_ROOT_PASSWORD=123456 mysql:5.7.5
#mysql data目录
docker cp mysql-test:/var/lib/mysql /usr/local/src/dockercontain/mysql
#mysql配置目录
docker cp mysql-test:/etc/mysql/conf.d /usr/local/src/dockercontain/mysql
4.重新运行容器
docker rm -f mysql-test
docker run -itd --name mysql-test -v /usr/local/src/dockercontain/mysql/data:/var/lib/mysql -v /usr/local/src/dockercontain/mysql/conf.d:/etc/mysql/conf.d -p 3306:3306 -e MYSQL_ROOT_PASSWORD=123456 mysql:5.7.5
4.添加用户授权远程登录
docker exec -it mysql-test bash
mysql -u root -p
ALTER USER 'root'@'localhost' IDENTIFIED BY '123456';
CREATE USER 'admin'@'localhost' IDENTIFIED BY '123456';
grant all privileges on *.* to admin;
grant all privileges on *.* to 'root'@'%' identified by 'root' with grant option;
grant all privileges on *.* to 'admin'@'%' identified by 'root' with grant option;
网友评论