1、创建宿主机器的挂载目录
/opt/docker/mysql/conf
/opt/docker/mysql/data
/opt/docker/mysql/logs
2、创建【xxx.cnf】配置文件,内容如下所示:
[mysqld]
#服务唯一Id
server-id = 1
port = 3306
log-error = /var/log/mysql/error.log
#只能用IP地址
skip_name_resolve
#数据库默认字符集
character-set-server = utf8mb4
#数据库字符集对应一些排序等规则
collation-server = utf8mb4_general_ci
#设置client连接mysql时的字符集,防止乱码
init_connect='SET NAMES utf8mb4'
#最大连接数
max_connections = 300
3、执行创建mysql容器命令
docker run --name xsy_mysql \
--restart always \
--privileged=true \
-p 3306:3306 \
-v /opt/docker/mysql/conf:/etc/mysql/conf.d \
-v /opt/docker/mysql/data:/var/lib/mysql \
-v /opt/docker/mysql/logs:/var/log/mysql \
-e MYSQL_ROOT_PASSWORD=rootxxx \
-d daocloud.io/library/mysql:5.7.5