1. 镜像及目录

docker pull mysql:9.0.1

mkdir -p /elf/mysql/{conf,data} && \
	cd /elf/mysql/conf && \
	vim /elf/mysql/conf/my.cnf

2. 配置文件

  • Zabbix:[mysqld]:log_bin_trust_function_creators = 1

show variables like 'log_bin';

show variables like '%log_bin_trust_function_creators%';
[mysqld]
# zabbix
log_bin_trust_function_creators = 1

# 服务端端口
port=3306

# mysql 安装目录
basedir=/elf/mysql

# mysql 数据目录
datadir=/elf/mysql/data

lc_messages_dir=/usr/share/mysql

lc_messages=zh_CN

# 允许最大连接数
max_connections=1000

# 允许连接失败的次数
max_connect_errors=100

# 服务器端默认字符集
character-set-server=utf8mb4

# 存储引擎
default-storage-engine=InnoDB

# sql语句是否敏感:1:不敏感
lower_case_table_names = 1

# 严格的日期时间类型
explicit_defaults_for_timestamp=1

[mysql]
default-character-set=utf8mb4

[client]
port=3306

default-character-set=utf8mb4

3. 启动容器

docker run \
	--name mysql \
	-p 3306:3306 \
	--privileged=true \
	--net network-common \
	-v /elf/mysql/data:/var/lib/mysql \
	-v /elf/mysql/conf:/etc/mysql/conf.d \
	-e MYSQL_ROOT_PASSWORD=cipher \
	-itd mysql:9.0.1 \
	--character-set-server=utf8mb4 \
	--collation-server=utf8mb4_unicode_ci
-e MYSQL_DATABASE="zabbix" \
-e MYSQL_USER="zabbix_user" \
-e MYSQL_PASSWORD="zabbix_cipher" \
-e MYSQL_ROOT_PASSWORD="cipher" \

-itd mysql:9.0.1 \
--character-set-server=utf8mb4 \
--collation-server=utf8mb4_unicode_ci \
--default-authentication-plugin=mysql_native_password

4. 账户权限设置

docker exec -it mysql bash

mysql -u root -p

create database elf charset utf8mb4 collate utf8mb4_general_ci;

create user 'elf_user' identified by 'elf_cipher';

grant all privileges on elf.* to 'elf_user';

flush privileges;