优化mysql的镜像,默认配置和自定义配置分离,并且修改说明文档

This commit is contained in:
KennyLee 2019-04-18 11:00:01 +08:00
parent 7bedc4150f
commit efddbc08ba
4 changed files with 30 additions and 24 deletions

View File

@ -6,16 +6,17 @@
修改:
1. 修改默认mysql默认编码为utf-8
2. 可自行修改my.cnf进行构建
1. 修改官网的my.cnf文件配置编码为utf-8
2. 增加/etc/mysql/mysql-my.conf.d/的配置目录方便启动容器的时候映射额外mysql的配置目录。
3. 去掉默认的 VOLUME /var/lib/mysql 方便备份。
### 配置
### 自定义配置
* 最大连接数可参考下docker-compose.yml启动容器的时候传入`--max_connections=300`参数配置即可。
1. 在宿主机上映射镜像内部的`/etc/mysql/mysql-my.conf.d/`目录然后创建cnf文件再把自定义的配置填写在里面。
2. 启动容器的时候通过cmd的方法传入配置。例如最大连接数可参考下docker-compose.yml启动容器的时候传入`--max_connections=300`参数配置即可。
### 阿里云构建的镜像
### 镜像下载
```
docker pull registry.cn-hangzhou.aliyuncs.com/kennylee/mysql

19
mysql/conf/mysqld.cnf Normal file
View File

@ -0,0 +1,19 @@
[mysqld]
# 开启binlog
server-id = 1
log-bin = /var/log/mysql/mysql-bin.log
binlog_format = MIXED
# 自动删除7天之前的binlog
expire_logs_days = 7
# 开启慢查询日志配置
slow_query_log = 1
slow_query_log_file = /var/log/mysql/mysql-slow-queries.log
# 超过定义为慢查询
long_query_time = 4
# 日志输出方式
#log_output = FILE,TABLE
#
# 未使用索引的查询也被记录到慢查询日志中
#log_queries_not_using_indexes = 1

View File

@ -12,7 +12,8 @@ services:
- MYSQL_ROOT_PASSWORD=111111
volumes:
- ./data/standalong:/var/lib/mysql/:z
#- ./data/standalong-logs:/var/log/mysql/:z
- ./conf/:/etc/mysql/mysql-my.conf.d/:z
- ./data/standalong-logs:/var/log/mysql/:z
command: ["--max_connections=300"]
logging:
driver: 'json-file'

View File

@ -61,25 +61,10 @@ sql_mode = NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
# 开启binlog
server-id = 1
log-bin = /var/log/mysql/mysql-bin.log
binlog_format = MIXED
# 自动删除7天之前的binlog
expire_logs_days = 7
# 慢查询配置
slow_query_log = 1
slow_query_log_file = /var/log/mysql/mysql-slow-queries.log
# 超过定义为慢查询
long_query_time = 4
# 日志输出方式
# log_output = FILE,TABLE
# 未使用索引的查询也被记录到慢查询日志中
log_queries_not_using_indexes = 1
# * IMPORTANT: Additional settings that can override those from this file!
# The files must end with '.cnf', otherwise they'll be ignored.
#
!includedir /etc/mysql/conf.d/
# 自定义扩展mysql的配置可以写在这里优先级最高
!includedir /etc/mysql/mysql-my.conf.d/