分享一个 mysql 的 docker-compose.yml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
| version: "3" services: db: restart: always container_name: mysql command: --lower_case_table_names=1 --character-set-server=utf8mb4 --collation-server=utf8mb4_general_ci --explicit_defaults_for_timestamp=true image: mysql environment: TZ: Asia/Shanghai MYSQL_ROOT_PASSWORD: crm@8888 ports: - 3306:3306 volumes: - /usr/local/docker/mysql/data:/var/lib/mysql - /usr/local/docker/mysql/config:/etc/mysql/conf.d
|
说明
- /usr/local/docker/mysql/data:/var/lib/mysql
这里是映射 mysql 的 data 目录
- /usr/local/docker/mysql/config:/etc/mysql/conf.d
这里是映射 mysql 的配置文件 (路径创建后需要自己手动添加 conf.d)
mysql 常用命令
1 2 3 4 5
| -- 创建用户 CREATE USER 'username'@'%' IDENTIFIED BY 'password';
-- 授权使用数据库 GRANT ALL ON *.* TO 'username'@'%';
|
参考文档
docker-hub-mysql
这里的就是 csdn 上一个作者的文章,我直接搬运过来了
原文链接
mysql5
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
| version: '3.1' services: mysql: restart: always image: mysql:5.7.22 container_name: mysql ports: - 3306:3306 environment: TZ: Asia/Shanghai MYSQL_ROOT_PASSWORD: 123456 command: --character-set-server=utf8mb4 --collation-server=utf8mb4_general_ci --explicit_defaults_for_timestamp=true --lower_case_table_names=1 --max_allowed_packet=128M --sql-mode="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:
|
mysql8
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
| version: '3.1' services: db: image: mysql restart: always environment: 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 ports: - 3306:3306 volumes: - ./data:/var/lib/mysql
adminer: image: adminer restart: always ports: - 8080:8080
|