现象:
docker-compose 启动mysql时,mysql正常启动,但是配置文件不能生效。
docker-compose配置文件如下:
version: '3'
services:
mysql:
restart: always
image: mysql:5.7
container_name: mysql
volumes:
# - ./mydir:/mydir
- ./datadir/:/var/lib/mysql/
- ./conf/my.cnf:/etc/my.cnf
environment:
- "MYSQL_ROOT_PASSWORD=123456"
# - "MYSQL_DATABASE=mydb"
- "TZ=Asia/Shanghai"
ports:
- 3306:3306
mysql 配置文件:
[client]
port = 3306
socket=/var/lib/mysql/mysql.sock
[mysqld]
datadir=/var/lib/mysql
max_allowed_packet = 256M
character_set_server= utf8
max_binlog_size=512M
max_connect_errors =102400
max_connections = 4096
max_user_connections = 3072
socket=/var/lib/mysql/mysql.sock
log-error=/var/log/mysql/mysqld.log
lower_case_table_names=1
[mysqldump]
max_allowed_packet = 128M
[mysql]
no-auto-rehash
prompt = \\u@\\d \\r:\\m:\\s>
[myisamchk]
key_buffer_size = 32M
sort_buffer_size = 32M
read_buffer = 8M
write_buffer = 8M
[mysqlhotcopy]
interactive-timeout
问题根因:
进入容器登陆mysql,发现如下提示。才发现是因为配置文件权限太大的原因。mysql自动忽略了配置建。
问题解决:
修改配置文件的权限,重启docker-compose 即可。
chmod 644./conf/my.cnf
问题总结:
遇到问题,需要多看输出信息。就能发现问题的端倪。