创建配置文件
docker容器内部:/etc/mysql/my.conf 里面配置如下:
!includedir /etc/mysql/conf.d/ !includedir /etc/mysql/mysql.conf.d/ 这里包含了一个默认配置,如下:mysqld.cnf
[mysqld]
pid-file = /var/run/mysqld/mysqld.pid
socket = /var/run/mysqld/mysqld.sock
datadir = /var/lib/mysql
#log-error = /var/log/mysql/error.log
# By default we only accept connections from localhost
#bind-address = 127.0.0.1
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
所以,我们可以在宿主机内部 /data/mysql/conf.d
创建配置文件 my.cnf
创建容器
docker run -di \
--name mysql \
-p 3306:3306 \
-v /data/mysql/data:/var/lib/mysql \
-v /data/mysql/conf.d:/etc/mysql/conf.d \
-e MYSQL_ROOT_PASSWORD=123456 \
mysql:5.7.23