mysql.yml

 

2023-02-19

Docker Compose 配置文件:

1
version: "3.7"
2
3
services:
4
mysql:
5
image: "mysql:latest"
6
restart: always
7
container_name: "mysql"
8
volumes:
9
- "/opt/mysql/data:/var/lib/mysql"
10
- "/opt/mysql/log:/var/log/mysql"
11
- "/opt/mysql/conf/:/etc/mysql/conf.d"
12
environment:
13
MYSQL_USER: "username"
14
MYSQL_PASSWORD: "password"
15
MYSQL_DATABASE: "test"
16
MYSQL_ROOT_PASSWORD: "root_password"
17
command: "--default-authentication-plugin=mysql_native_password"
18
ports:
19
- "64406:3306"
  • command:
    • —default-authentication-plugin=mysql_native_password: 防止老版本客户端报错
  • volumes:
    • /var/lib/mysql: 数据
    • /etc/mysql/conf.d: 配置文件
    • /docker-entrypoint-initdb.d: 初始化脚本
  • environment
    • MYSQL_USER: 要创建的用户
    • MYSQL_PASSWORD: 对应密码
    • MYSQL_DATABASE: 创建数据库
    • MYSQL_ROOT_PASSWORD: root 密码