下载镜像
docker pull mysql
创建挂载目录
#挂载目录
mkdir -p /data/docker/mysql/conf
mkdir -p /data/docker/mysql/data
mkdir -p /data/docker/mysql/logs
MySQL配置文件
vim /data/docker/mysql/conf/mysql.conf
内容
[mysql]
port = 3306
character-set-server=utf8
docker-compose.yml文件
mkdir -p /data/docker-compose/mysql/
vim /data/docker-compose/mysql/docker-compose.yml
内容
version: '3.1'
services:
db:
image: mysql
restart: always
container_name: mysql
environment:
MYSQL_ROOT_PASSWORD: 123456
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
ports:
- 3306:3306
volumes:
- /data/docker/mysql/data:/var/lib/mysql
- /data/docker/mysql/conf:/etc/mysql/conf.d
- /data/docker/mysql/logs:/logs
运行
docker-compose up -d
测试
docker ps
docker logs -f mysql
docker exec -it mysql bash
mysql -u root -p
输入密码