os:ubuntu20.04
docker:v24
docker-compose:v2.2.2
主要步骤
1.拉取镜像
docker pull mysql:8.0.20
2.创建目录
mkdir -p /data/docker_mysql/log
mkdir -p /data/docker_mysql/data
mkdir -p /data/docker_mysql/conf.d
3.创建配置文件
touch /data/docker_mysql/conf.d/my.cnf
cat > /data/docker_mysql/conf.d/my.cnf <<EOF
###### [client]配置模块 ######
[client]
default-character-set=utf8mb4
socket=/var/lib/mysql/mysql.sock
###### [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