docker上面安装mysql5.7
时间: 2023-08-17 08:14:25 浏览: 119
Docker安装mysql
要在Docker上安装MySQL 5.7,可以按照以下步骤进行操作:
1. 首先,使用以下命令创建需要挂载的目录:
```
mkdir -p /usr/local/docker/mysql5.7/conf
mkdir -p /usr/local/docker/mysql5.7/data
mkdir -p /usr/local/docker/mysql5.7/log
```
2. 停止并删除之前创建的MySQL 5.7容器:
```
docker stop mysql5.7
docker rm mysql5.7
```
3. 接下来,使用以下命令创建新的MySQL 5.7容器,并挂载指定的目录:
```
docker run -p 3315:3306 --name mysql5.7 \
-v /usr/local/docker/mysql5.7/conf:/etc/mysql/mysql.conf.d \
-v /usr/local/docker/mysql5.7/log:/var/log/ \
-v /usr/local/docker/mysql5.7/data:/var/lib/mysql \
-e MYSQL_ROOT_PASSWORD=asd123456 \
-d mysql:5.7
```
这将创建一个名为mysql5.7的容器,将宿主机的目录`/usr/local/docker/mysql5.7/conf`挂载到容器内的`/etc/mysql/mysql.conf.d`目录,将`/usr/local/docker/mysql5.7/log`挂载到容器内的`/var/log/`目录,将`/usr/local/docker/mysql5.7/data`挂载到容器内的`/var/lib/mysql`目录。同时,设置了MySQL的root密码为`asd123456`。
现在,您已经成功在Docker上安装了MySQL 5.7,并且数据和配置都被持久化到了宿主机上。
#### 引用[.reference_title]
- *1* [Docker安装MYSQL5.7](https://blog.csdn.net/C_0010/article/details/127932039)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item]
- *2* *3* [docker下安装mysql5.7教程](https://blog.csdn.net/weixin_44947701/article/details/125957909)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item]
[ .reference_list ]
阅读全文