一、(我的电脑不需要)下载wsl2需要的linux内核:
参考:https://docs.microsoft.com/zh-cn/windows/wsl/wsl2-kernel
二、windows中安装和设置docker desktop
参考:https://blog.csdn.net/m0_68988603/article/details/123884239
三、安装mysql并启动
参考:https://blog.csdn.net/ma_jiang/article/details/88431839?spm=1001.2101.3001.6650.2&utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7ERate-2-88431839-blog-126778443.pc_relevant_3mothn_strategy_and_data_recovery&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7ERate-2-88431839-blog-126778443.pc_relevant_3mothn_strategy_and_data_recovery&utm_relevant_index=5
设置mysql可被外部访问
参考:https://blog.csdn.net/XG17_38241417145/article/details/122668368?utm_medium=distribute.pc_relevant.none-task-blog-2~default~baidujs_baidulandingword~default-0-122668368-blog-128048538.pc_relevant_3mothn_strategy_recovery&spm=1001.2101.3001.4242.1&utm_relevant_index=3
参考:https://blog.csdn.net/LlewynDav/article/details/125373155
1、控制面板->程序->启用或关闭Windows功能->向下滑
勾选 适用于Linux的 Windows子系统 和 虚拟机平台
将WSL2设置为默认版本:管理员身份运行Windows PowerShell,运行下面的命令。
wsl --set-default-version 2
安装Docker Desktop for Windows
2、设置默认安装到c盘为D盘(将默认的路径映射到D盘)
mklink /j "C:\Users\Administrator\AppData\Local\Docker" "D:\Program Files\Docker\DockerData"
mklink /j "C:\Users\Administrator\AppData\Local\Docker" "D:\Program Files\DockerData"
3、设置镜像(右键docker小鲸鱼)
"registry-mirrors": [
"https://52qrdrjd.mirror.aliyuncs.com",
"https://docker.mirrors.ustc.edu.cn",
"http://f1361db2.m.daocloud.io",
"https://registry.docker-cn.com"
]
4、镜像保存位置调整到D盘
4.1、备份数据到另一个文件夹
wsl --export docker-desktop-data "D:\Program Files\DockerData\wsl\data\docker-desktop-data.tar"
wsl --export docker-desktop "D:\Program Files\DockerData\wsl\distro\docker-desktop.tar"
4.2、删除原有数据
wsl --unregister docker-desktop-data
4.3、更改数据存储盘并恢复数据
wsl --import docker-desktop-data "C:\Users\Administrator\AppData\Local\Docker\wsl\data" "D:\Program Files\DockerData\wsl\data\docker-desktop-data.tar"
wsl --import docker-desktop "C:\Users\Administrator\AppData\Local\Docker\wsl\distro" "D:\Program Files\DockerData\wsl\distro\docker-desktop.tar"
5、mysql启动docker run --name mysql --restart=always -v D:/Docker/mysql/conf:/etc/mysql/conf.d -v d:/Docker/mysql/data:/var/lib/mysql -p 3306:3306 -e MYSQL_ROOT_PASSWORD=123456 -d mysql
docker run -p 13306:3306 --name mysql --restart=always -e MYSQL_ROOT_PASSWORD=123456 -v D:/docker/mysql/data:/var/lib/mysql -v D:/docker/mysql/log:/var/log/mysql -v D:/docker/mysql/conf/my.cnf:/etc/mysql/my.cnf -v /etc/localtime:/etc/localtime -d mysql:8.0.30
docker run -p 13306:3306 --name mysql --restart=always -e MYSQL_ROOT_PASSWORD=123456 -v D:/docker/mysql/data:/var/lib/mysql -v D:/docker/mysql/log:/var/log/mysql -v D:/docker/mysql/conf/my.cnf:/etc/mysql/my.cnf -v D:/docker/mysql/conf/conf.d:/etc/mysql/conf.d -v /etc/localtime:/etc/localtime -d mysql:8.0.30
6、设置权限
CREATE USER 'XXX'@'%' IDENTIFIED BY '123456';
grant all privileges on *.* to XXX@'%' identified by '123456' with grant option;
mysql8版本以后 不用 【identified by `密码`】,直接用下面
GRANT ALL PRIVILEGES ON *.* TO XXX@'%' WITH GRANT OPTION;
flush privileges;