OR博客
登录
Docker入门(三)Docker Compose部署MySQL
苗锦洲
创建于:
2021-09-27 16:52:57
0
29
205
0
Docker Compose在master上部署MySQL
容器化
Docker-Compose
MySQL
友情提示:
此篇文章大约需要阅读
5分14秒
# Docker入门系列 [Docker入门(一)安装Docker - 苗锦洲的个人博客 (ordinaryroad.top)](https://ordinaryroad.top/article/52.html) [Docker入门(二)安装Docker-Compose (ordinaryroad.top)](https://ordinaryroad.top/article/53.html) [Docker入门(三)Docker Compose部署MySQL - 苗锦洲的个人博客 (ordinaryroad.top)](https://ordinaryroad.top/article/54.html) [Docker入门(四)Docker Compose部署Redis - 苗锦洲的个人博客 (ordinaryroad.top)](https://ordinaryroad.top/article/55.html) [Docker入门(五)Docker Compose部署Spring Boot访问MySQL - 苗锦洲的个人博客 (ordinaryroad.top)](https://ordinaryroad.top/article/56.html) # 构建目录规划 ```bash [root@master mysql]# tree . ├── conf │ └── my.cnf ├── db └── docker-compose.yml 2 directories, 2 files ``` # my.cnf配置 ```bash [mysqld] user=mysql default-storage-engine=INNODB character-set-server=utf8 [client] default-character-set=utf8 [mysql] default-character-set=utf8 ``` # docker-compose.yml配置 ```yaml version: '3.0' services: mysql: # network_mode: "host" environment: MYSQL_ROOT_PASSWORD: "root" MYSQL_USER: 'test' MYSQL_PASS: 'test' image: "docker.io/mysql:latest" container_name: "mysql8.0" restart: always volumes: - "./db:/var/lib/mysql" - "./conf/my.cnf:/etc/my.cnf" # - "./init:/docker-entrypoint-initdb.d/" ``` # 启动 ```bash docker-compose up -d ``` # 查看容器启动状态 ```bash docker ps ``` ```bash CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 6e4479df35de mysql:latest "docker-entrypoint.s…" 4 minutes ago Up 4 minutes mysql8.0 ``` # 进入容器 ```bash docker exec -it 6e4479df35de bash ``` # 登录MySQL ```bash mysql -uroot -p ``` ```bash Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 8 Server version: 8.0.26 MySQL Community Server - GPL Copyright (c) 2000, 2021, 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. ``` # 查询数据库 ```bash mysql> show databases; ``` ```bash +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | | sys | +--------------------+ 4 rows in set (0.00 sec) ``` # 可以使用其他工具连接 root/root,端口3306
本文作者:
苗锦洲
本文链接:
版权声明:
本文为OrdinaryRoad博客博主 苗锦洲 的原创文章,遵循
CC BY-SA 4.0
许可协议,转载请附上本文链接及本声明。
上一篇
Docker入门(二)安装Docker-Compose
下一篇
Docker入门(四)Docker Compose部署Redis
评论
楼主暂时不想被别人评论哦~
回复
已自动恢复阅读位置、日/夜间模式参数
从头开始