安装mysql docker-compose.yml参考配置


# 主从库
version : '3.8'
services:
  slave-mysql:
    container_name: slave-mysql
    image: mysql:5.7
    build:
      context: ./mysql
      dockerfile: dockerfile
    ports:
      - "13335:3335"
    volumes:
      - ./mysql/conf:/etc/mysql/conf.d
      - ./mysql/logs:/logs
      - ./mysql/data:/var/lib/mysql
      - ./mysql/db:/docker-entrypoint-initdb.d/
      - /etc/localtime:/etc/localtime
      - /etc/timezone:/etc/timezone
    command: [
          'mysqld',
          '--innodb-buffer-pool-size=80M',
          '--character-set-server=utf8mb4',
          '--collation-server=utf8mb4_unicode_ci',
          '--default-time-zone=+8:00',
          '--lower-case-table-names=1'
        ]
    environment:
      MYSQL_DATABASE: test
      MYSQL_ROOT_PASSWORD: root
      MYSQL_USER: test
      MYSQL_PASSWORD: 123456
    #privileged: true
    restart: always

my.cnf

[mysqld]
default-storage-engine=INNODB
character-set-server=utf8
collation-server=utf8_general_ci
init_connect='SET NAMES utf8'


#binlog格式
binlog_format = mixed
#存放地址,注意这个地址是docker容器里面的地址,不是宿主机里面的地址
log-bin=/var/lib/mysql/mysql-bin
server-id=33
#存放时间
expire_logs_days=30
#最大文件大小
max_binlog_size=50m
#缓存大小
binlog_cache_size=10m
#最大缓存大小
max_binlog_cache_size=512m

#主从设置-开始
#log-bin=mysql-bin
#server-id=37
#主从设置-结束

#慢查询
slow_query_log=1
slow_query_log_file=/logs/test-slow.log



[client]
default-character-set=utf8

[mysql]
default-character-set=utf8
This entry was posted in 应用. Bookmark the permalink.

发表评论