MySQL docker compose安装配置

docker-compose.yml

version: '1'
services:
  mysql:
    restart: always
    privileged: true
    image: mysql:8.0.21
    container_name: mysqlServer3306
    volumes:
      - ./db:/var/lib/mysql
      - ./conf:/etc/mysql/conf.d
      - ./logs:/logs
    command:
      --character-set-server=utf8mb4
      --collation-server=utf8mb4_general_ci
      --explicit_defaults_for_timestamp=true
    environment:
      MYSQL_ROOT_PASSWORD: "123456"
      MYSQL_USER: "test"
      MYSQL_PASSWORD: "123456"
      MYSQL_INITDB_SKIP_TZINFO: "Asia/Shanghai"
    ports:
      - 3306:3306
    network_mode: "bridge"

conf\my.cnf

###### [mysql]配置模块 ######
[mysql]
# 设置MySQL客户端默认字符集
default-character-set=utf8mb4
socket=/var/lib/mysql/mysql.sock


###### [mysqld]配置模块 ######
[mysqld]
port=3306
user=mysql

sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION

datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock

# MySQL8 的密码认证插件
default_authentication_plugin=mysql_native_password

# 禁用符号链接以防止各种安全风险
symbolic-links=0

# 允许最大连接数
max_connections=1000

# 服务端使用的字符集默认为8比特编码的latin1字符集
character-set-server=utf8mb4

# 创建新表时将使用的默认存储引擎
default-storage-engine=INNODB

# 表名存储在磁盘是小写的,但是比较的时候是不区分大小写
lower_case_table_names=0
max_allowed_packet=16M 

# 设置时区
default-time_zone='+8:00'

# binlog 配置
log-bin = /logs/mysql-bin.log
expire-logs-days = 90
max-binlog-size = 500M

# server-id 配置
server-id = 1


###### [client]配置模块 ######
[client]
default-character-set=utf8mb4

你可能感兴趣的:(docker-compose,mysql,docker,数据库)