创建docker-compose.yml启动文件、my.cnf配置文件、映射文件夹,结构如下:
mysql
docker-compose.yml
logs
db
conf
my.cnf
docker-compose.yml内容
version: '3'
services:
mysql:
restart: always
privileged: true
image: mysql
container_name: mysql
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: "Jiangk.123"
MYSQL_USER: "canal"
MYSQL_PASSWORD: "canal"
MYSQL_INITDB_SKIP_TZINFO: "Asia/Shanghai"
ports:
- 3306:3306
network_mode: "bridge"
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
binlog_format=ROW
# server-id 配置
server-id = 1
#不同步的数据库,可设置多个
binlog-ignore-db=information_schema
binlog-ignore-db=performance_schema
binlog-ignore-db=mysql
###### [client]配置模块 ######
[client]
default-character-set=utf8mb4
启动mysql服务
docker-compose up -d