Mysql 5.7
docker-compose.yml
version: '3.1'
services:
mysql5.7:
image: mysql:5.7.33
command: --default-authentication-plugin=mysql_native_password
restart: always
environment:
- TZ=Asia/Shanghai
- MYSQL_ROOT_PASSWORD=root
- MYSQL_DATABASE=初始数据库
volumes:
- ./mysql/mysql5.7/my.cnf:/etc/mysql/my.cnf
- ./mysql/mysql5.7/data:/var/lib/mysql
ports:
- 3306:3306
下面简单说下重要参数作用:
- MYSQL_DATABASE:初始化数据库,比如定义 demo,那么在容器启动后,会自动创建一个 demo 的数据库
- TZ=Asia/Shanghai:控制该容器的时区
my.cnf 如果需要配置的话,可以使用如下的配置
[client]
default-character-set = utf8mb4
[mysql]
default-character-set = utf8mb4
[mysqld]
character-set-client-handshake = FALSE
character-set-server = utf8mb4
collation-server = utf8mb4_general_ci
lower_case_table_names=1
max_allowed_packet=32M
max_connections=1024
open_files_limit=65535
tmp_table_size=124M
interactive_timeout=300
max_connect_errors=10000
group_concat_max_len=2048
thread_cache_size=20
thread_stack=192K
transaction-isolation = READ-COMMITTED
key_buffer_size=128M
read_buffer_size=8M
read_rnd_buffer_size=16M
join_buffer_size=16M
sort_buffer_size=16M
max_heap_table_size=123M
Mysql 8.0
Mysql 8.0 官方文档、docker mysql 官方文档
docker-compose.yml
version: '3.1'
services:
mysql8_01:
container_name: mysql8_01
image: mysql:8.0
command: --default-authentication-plugin=mysql_native_password
restart: always
environment:
TZ: Asia/Shanghai
MYSQL_ROOT_PASSWORD: root
volumes:
# - ./mysql8_01/my.cnf:/etc/mysql/my.cnf
- ./mysql8_01/data:/var/lib/mysql
ports:
- 3306:3306
- 配置文件暂无。