Docker安装Mysql找不到配置文件问题

问题:

CentOS7上使用Docker安装Mysql容器作为数据库,但因Linux中Mysql默认是表名大小写敏感的,导致项目启动失败。要修改表名大小写敏感设置时发现找不到Mysql配置文件(my.cnf)。

解决:

在创建容器时以指定配置文件的方式创建:
例:

docker run -p 3306:3306 --name mysql \
-v /usr/local/docker/mysql/logs:/var/log/mysql \
-v /usr/local/docker/mysql/data:/var/lib/mysql \
-v /usr/local/docker/mysql/conf/my.cnf:/etc/mysql/mysql.conf.d/mysqld.cnf \
-e MYSQL_ROOT_PASSWORD=123456 \
-d mysql:5.7

其中,需提前在/usr/local/docker/mysql/conf下创建my.cnf:
例:

[mysql]
#设置mysql客户端默认字符集
default-character-set=utf8
socket=/var/lib/mysql/mysql.sock

[mysqld]
#修改大小写敏感
skip-grant-tables
lower_case_table_names=1
#mysql5.7以后的不兼容问题处理
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
# Settings user and group are ignored when systemd is used.
# If you need to run mysqld under a different user or group,
# customize your systemd unit file for mariadb according to the
# instructions in http://fedoraproject.org/wiki/Systemd
#允许最大连接数
max_connections=200
#服务端使用的字符集默认为8比特编码的latin1字符集
character-set-server=utf8
#创建新表时将使用的默认存储引擎
default-storage-engine=INNODB
lower_case_table_names=1
max_allowed_packet=16M 
#设置时区
default-time_zone='+8:00'
[mysqld_safe]
log-error=/var/log/mariadb/mariadb.log
pid-file=/var/run/mariadb/mariadb.pid

#
# include all files from the config directory
#
#!includedir /etc/mysql/conf.d/
#!includedir /etc/mysql/mysql.conf.d/

你可能感兴趣的:(Docker安装Mysql找不到配置文件问题)