Mysql主要用于存储数据
运行环境:
CentOS 7.4 64位
1、创建存放docker-compose目录
mkdir -p /usr/local/docker
2、进入存放docker-compose目录
cd usr/local/docker
3、创建docker-compose.yml
touch docker-compose.yml
4、编写docker-compose.yml
version: '3.1'
services:
mysql:
restart: always
image: mysql:5.7.25
container_name: mysql
ports:
- 3306:3306
environment:
TZ: Asia/Shanghai
MYSQL_ROOT_PASSWORD: '123456'
command:
--default-authentication-plugin=mysql_native_password
--character-set-server=utf8mb4
--collation-server=utf8mb4_general_ci
--explicit_defaults_for_timestamp=true
--lower_case_table_names=1
--max_allowed_packet=128M
--sqlmode="STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION,NO_ZERO_DATE,NO_ZERO_IN_DATE,ERROR_FOR_DIVISION_BY_ZERO"
volumes:
- mysql-data:/var/lib/mysql
volumes:
mysql-data:
5、启动MySQL
docker-compose up -d
完成启动
Creating mysql ... done
6、Navicat连接MySQL容器
Navicat连接MySQL容器.png