5.7.*版本
version: '3.1'
services:
db:
restart: always
image: mysql:5.7.22
container_name: mysql_5.7
ports:
- 3306:3306
environment:
TZ: Asia/Shanghai
MYSQL_ROOT_PASSWORD: 123456
command:
--character-set-server=utf8mb4
--collation-server=utf8mb4_general_ci
--explicit_defaults_for_timestamp=true
--lower_case_table_names=1
--max_allowed_packet=128M
--sql-mode="STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION,NO_ZERO_DATE,NO_ZERO_IN_DATE,ERROR_FOR_DIVISION_BY_ZERO"
volumes:
- ./data:/var/lib/mysql
8.0.*版本
version: '3'
services:
mysql8.0:
image: mysql8.0
restart: always
container_name: mysql8.0
privileged: true # 解决可能出现创建文件的权限问题
ports:
- 3307:3306
environment:
TZ: Asia/Shanghai
MYSQL_ROOT_PASSWORD: 123456
volumes:
- ./data:/var/lib/mysql
- ./conf:/etc/mysql
command:
--default-authentication-plugin=mysql_native_password
--character-set-server=utf8mb4
--collation-server=utf8mb4_general_ci
--explicit_defaults_for_timestamp=true
--lower_case_table_names=1
注意修改隔离级别(重启也不会失效)
/etc/mysql/conf.d/docker.cnf
[mysqld]
skip-host-cache
skip-name-resolve
transaction_isolation=read-committed ## 重点是添加这句。不然是REPEATABLE-READ可重复读的隔离级别。
临时需改
select @@global.transaction_isolation,@@transaction_isolation;
SET GLOBAL TRANSACTION ISOLATION LEVEL READ COMMITTED;
SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED;
select @@global.transaction_isolation,@@transaction_isolation;