docker-compose.yml
version: '3'
services:
mysql:
restart: always
image: mysql:5.7
container_name: mysql
command: --default-authentication-plugin=mysql_native_password #解决外部无法访问
volumes:
- ./mydir:/mydir
- ./datadir:/var/lib/mysql
- ./conf/my.cnf:/etc/my.cnf
# 数据库还原目录 可将需要还原的sql文件放在这里
- /docker/mysql/source:/docker-entrypoint-initdb.d
environment:
- MYSQL_ROOT_PASSWORD=password
- TZ=Asia/Shanghai
ports:
- 3306:3306
my.cnf
[mysqld]
user=mysql
default-storage-engine=INNODB
character-set-server=utf8
[client]
default-character-set=utf8
[mysql]
default-character-set=utf8