在Windows Docker中安装MySQL
2021/6/13 19:24:51
本文主要是介绍在Windows Docker中安装MySQL,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
本文的前提是本地Docker环境已经配置成功,参考Windows 10安装Docker并使用私钥连接AWS EC2
1. 参考资料
https://dev.mysql.com/doc/refman/8.0/en/grant.html
https://www.jeffgeerling.com/blog/2017/how-fix-host-1721801-not-allowed-connect-mysql-docker
https://hub.docker.com/_/mysql?tab=description&page=5&ordering=last_updated
2. 运行docker pull mysql:5.7.34
下载image
5.7.34: Pulling from library/mysql 69692152171a: Pull complete 1651b0be3df3: Pull complete 0f86c95aa242: Pull complete 37ba2d8bd4fe: Pull complete 497efbd93a3e: Pull complete a023ae82eef5: Pull complete e76c35f20ee7: Pull complete e887524d2ef9: Pull complete ccb65627e1c3: Pull complete Digest: sha256:a682e3c78fc5bd941e9db080b4796c75f69a28a8cad65677c23f7a9f18ba21fa Status: Downloaded newer image for mysql:5.7.34 docker.io/library/mysql:5.7.34 d53b544bd61131e960f6983acfb3392a37283b5d469ce782c1f0210d71d7fadc
3. 启动MySQL
docker run -v {VOLUME PATH}:/var/lib/mysql --name test-mysql -p 3306:3306 -e MYSQL_ROOT_PASSWORD=123456 -d mysql:5.7.34
{VOLUME PATH}为数据持久化的位置,初始化时必须为空
4. 宿主机连接
5. 创建新用户和数据库
CREATE USER '{USERNAME}'@'%' IDENTIFIED BY '{PASSWORD}'; create database `{DATABASE}` GRANT ALL ON {DATABASE}.* TO '{USERNAME}'@'%';
6. 用新用户登录
docker exec -it {CONTAINER ID} mysql -u {USERNAME} -p
这篇关于在Windows Docker中安装MySQL的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-11-20部署MySQL集群入门:新手必读指南
- 2024-11-20部署MySQL集群教程:初学者指南
- 2024-11-20部署MySQL集群项目实战:新手教程
- 2024-11-20部署MySQL集群资料:新手入门教程
- 2024-11-20MySQL集群部署教程:入门级详解
- 2024-11-20MySQL集群教程:入门与实践指南
- 2024-11-20部署MySQL集群教程:新手入门指南
- 2024-11-20MySQL读写分离教程:轻松入门
- 2024-11-20部署MySQL集群入门:一步一步搭建你的数据库集群
- 2024-11-19部署MySQL集群学习:入门教程