参考Docker安装Mysql8.1.0_dokcer安装mysql8.1.0-CSDN博客
环境:centos7,docker26.1.3
文件位置
docker-compose.yml my.cnf文件分别在如图位置 注:8.1.0中docker-compose.yml中使用到../conf
创建data logs文件夹
创建my.cnf
###### [mysql]配置模块 ######
[mysql]
# 设置MySQL客户端默认字符集
default-character-set=utf8mb4
socket=/var/lib/mysql/mysql.sock
###### [mysqld]配置模块 ######
[mysqld]
port=3306
user=mysql
# 设置sql模式 sql_mode模式引起的分组查询出现*this is incompatible with sql_mode=only_full_group_by,这里最好剔除ONLY_FULL_GROUP_BY
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 的密码认证插件 如果不设置低版本navicat无法连接
default_authentication_plugin=mysql_native_password
# 禁用符号链接以防止各种安全风险
symbolic-links=0
# 允许最大连接数
max_connections=1000
# 服务端使用的字符集默认为8比特编码的latin1字符集
character-set-server=utf8mb4
# 创建新表时将使用的默认存储引擎
default-storage-engine=INNODB
# 0: 表名将按指定方式存储,并且比较区分大小写 1: 表名以小写形式存储在磁盘上,比较不区分大小写
lower_case_table_names=0
max_allowed_packet=16M
# 设置时区
default-time_zone='Asia/Shanghai'
# binlog 配置
binlog_format="ROW"
log-bin = /var/lib/mysql/mysql-bin
expire-logs-days = 90
max-binlog-size = 500M
# server-id 配置
server-id = 1
###### [client]配置模块 ######
[client]
default-character-set=utf8mb4
docker-compose.yml
version: '3'
services:
mysql:
image: mysql:latest
# restart: always
privileged: True
container_name: mysql8.1.0
volumes:
- ./data:/var/lib/mysql
- ../conf:/etc/mysql/conf.d
- ./logs:/logs
command:
--character-set-server=utf8mb4
--collation-server=utf8mb4_unicode_ci
--explicit_defaults_for_timestamp=true
environment:
MYSQL_ROOT_PASSWORD: "mysql"
# MYSQL_USER: "admin"
# MYSQL_PASSWORD: "admin"
# MYSQL_INITDB_SKIP_TZINFO: "Asia/Shanghai"
ports:
- "3306:3306"
network_mode: "bridge"
创建容器并后台启动-d
docker compose -f /home/xxx/docker/mysql/8.1.0/docker-compose.yml up -d
停止
docker compose -f /home/xxx/docker/mysql/8.1.0/docker-compose.yml stop
删除容器
docker compose -f /home/xxx/docker/mysql/8.1.0/docker-compose.yml down