Files
script/docker/compose/mysql/docker-compose.yml

19 lines
1.0 KiB
YAML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

version: '3.8' # 使用较新的版本,支持更多功能
services:
mysql:
image: registry.cn-hangzhou.aliyuncs.com/37/mysql:8
container_name: mysql # 容器名称
restart: always # 容器退出时自动重启
environment:
MYSQL_ROOT_PASSWORD: your_strong_root_password # 设置 root 用户密码,务必修改!
ports:
- "3306:3306" # 将容器的 3306 端口映射到宿主机的 3306 端口
volumes:
- ./data/mysql:/var/lib/mysql # 持久化存储 MySQL 数据
- ./data/my.cnf:/etc/mysql/conf.d/my.cnf # (可选) 挂载自定义配置文件
# (可选) 如果需要初始化 SQL 脚本
# volumes:
# - ./init.sql:/docker-entrypoint-initdb.d/init.sql # 启动时执行的初始化脚本
command: --default-authentication-plugin=mysql_native_password # (可选) 兼容旧客户端认证MySQL 8 默认使用 caching_sha2_password
# command: --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci # (可选) 设置默认字符集和排序规则