文章目录
思考:mysql的数据持久化问题,容器删除了不能删除数据
拉取mysql 镜像
docker pull mysql:5.7
查看镜像
➜ ~ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
mysql 5.7 2836a03e922f 43 hours ago 448MB
安装启动mysql容器,设置密码,设置挂载
-d
: 后台运行-p
: 端口映射-v
: 数据卷挂载-e
: 环境配置--name
: 容器名字
docker run -d -p 3310:3306 -v /Users/wyaoyao/mysql/conf:/etc/mysql/conf.d -v /Users/wyaoyao/mysql/data:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=wyy123 --name mysql01 mysql:5.7
登录mysql
➜ ~ mysql -h 127.0.0.1 -P 3310 -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 6
Server version: 5.7.32 MySQL Community Server (GPL)
Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.
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>