【windows Docker 安装mysql:只需3条命令】

如下

bash 复制代码
docker pull mysql
docker run --name mysql -p 3306:3306 -v D:/dockerFile/mysql/data:/var/lib/mysql/ -v D:/dockerFile/mysql/conf/my.cnf:/etc/mysql/my.cnf -e MYSQL_ROOT_PASSWORD=root -d mysql:latest --default-authentication-plugin=mysql_native_password
docker exec -it mysql/bin/bash
shell 复制代码
C:\Users\lxhjy>docker pull mysql
Using default tag: latest
latest: Pulling from library/mysql
8e0176adc18c: Pull complete
2d2c52718f65: Pull complete
d88d03ce139b: Pull complete
4a7d7f11aa1e: Pull complete
ce5949193e4c: Pull complete
f7f024dfb329: Pull complete
5fc3c840facc: Pull complete
509068e49488: Pull complete
cbc847bab598: Pull complete
942bef62a146: Pull complete
Digest: sha256:1773f3c7aa9522f0014d0ad2bbdaf597ea3b1643c64c8ccc2123c64afd8b82b1
Status: Downloaded newer image for mysql:latest
docker.io/library/mysql:latest

What's Next?
  1. Sign in to your Docker account → docker login
  2. View a summary of image vulnerabilities and recommendations → docker scout quickview mysql

C:\Users\lxhjy>docker run --name mysql -p 3306:3306 -v mysql-data:D:/dockerFile/mysql/data:/var/lib/mysql/ -v mysql-cnf:D:/dockerFile/mysql/conf/my.cnf:/etc/mysql/my.cnf -e MYSQL_ROOT_PASSWORD=root -d mysql:latest --default-authentication-plugin=mysql_native_password
docker: Error response from daemon: mount denied:
the source path "mysql-data:D:/dockerFile/mysql/data:/var/lib/mysql/"
too many colons.
See 'docker run --help'.

C:\Users\lxhjy>docker run --name mysql -p 3306:3306 -v D:/dockerFile/mysql/data:/var/lib/mysql/ -v D:/dockerFile/mysql/conf/my.cnf:/etc/mysql/my.cnf -e MYSQL_ROOT_PASSWORD=root -d mysql:latest --default-authentication-plugin=mysql_native_password
44e6fdfc6e135575ecd038be1c22e133e723a6fb01bd4b4228fafcc569423460

C:\Users\lxhjy>docker exec -it mysql/bin/bash
"docker exec" requires at least 2 arguments.
See 'docker exec --help'.

Usage:  docker exec [OPTIONS] CONTAINER COMMAND [ARG...]

Execute a command in a running container

C:\Users\lxhjy>docker exec -it mysql /bin/bash
bash-4.4# mysql -u root -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.2.0 MySQL Community Server - GPL

Copyright (c) 2000, 2023, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>

参考文章

https://blog.csdn.net/nmajsjpy/article/details/130183104?ops_request_misc=&request_id=&biz_id=102&utm_term=windows%20docker%20%E5%AE%89%E8%A3%85mysql%E6%98%A0%E5%B0%84%E5%9C%B0%E5%9D%80&utm_medium=distribute.pc_search_result.none-task-blog-2allsobaiduweb~default-1-130183104.142v96pc_search_result_base4&spm=1018.2226.3001.4187

相关推荐
扑火的小飞蛾1 小时前
生产级SOP:MySQL二进制安装与多实例部署实战(5.6/5.7/8.0/8.4全版本)
数据库·mysql·adb
遇码1 小时前
给 Rust 桌面应用做双击安装包:Windows NSIS setup.exe + macOS DMG 的完整做法
人工智能·windows·ai·rust·大模型
箓维2 小时前
MySQL_表的约束
android·数据库·mysql
东鹏特饮3 小时前
Docker 容器技术详细指南
运维·docker·容器
无级程序员4 小时前
dolphinscheduler3.x从mysql迁移到postgresql
数据库·mysql·postgresql
Vex2une5 小时前
笔记本电池健康校准与续航优化:循环次数查看、充电阈值与后台耗电控制
windows·笔记本·电源管理·电池校准·续航优化·电源选项
HEJOO95 小时前
MySQL 日期时间类型怎么选:DATE、DATETIME、TIMESTAMP、TIME、YEAR 全解析
android·数据库·mysql
开发者导航5 小时前
Tabby 教程:Docker 部署自托管 AI 编码助手
人工智能·docker·容器
Java码农也是农6 小时前
Docker 入门与实战:镜像、容器、数据卷和网络,用 Spring Cloud 部署讲清楚
网络·spring cloud·docker
codeejun7 小时前
每日一Go·MySQL-28、账户转账事务设计
开发语言·mysql·golang