问题遇到的现象和发生背景
使用docker-compose启动的mysql,启动的前几秒,内存一直在跳动,能达到16G的值,然后最后就稳定在16G
操作环境、软件版本等信息
Linux服务器
Mysql是5.7
docker-compose的配置
version: '3'
services:
mysql:
image: mysql:5.7
container_name: mysql5.7
restart: always
ports:
- "3306:3306"
environment:
- MYSQL_ROOT_PASSWORD=******
- TZ=Asia/Shanghai
volumes:
- ./mysql/my.cnf:/etc/mysql/my.cnf
- ./mysql/data:/var/lib/mysql
- ./mysql/conf.d:/etc/mysql/conf.d
my.cnf的配置
[client]
port=3306
socket=/var/lib/mysql/mysql.sock
[mysqld]
port=3306
socket=/var/lib/mysql/mysql.sock
pid-file=/var/run/mysqld/mysqld.pid
basedir=/usr
datadir=/var/lib/mysql
tmpdir=/tmp
#设置字符集和校对集
character-set-server=utf8mb4
collation-server=utf8mb4_general_ci
#服务器ID,用于复制设置
server-id=1
#设置查询缓存
query_cache_type=1
query_cache_size=64M
#InnoDB设置
innodb_buffer_pool_size=4G
innodb_log_file_size=512M
innodb_log_buffer_size=64M
innodb_flush_log_at_trx_commit=1
innodb_file_per_table=1
innodb_data_file_path=ibdata1:12M:autoextend
#最大连接数
max_connections=1000
#设置线程缓存
thread_cache_size=100
#错误日志路径
log_error=/var/log/mysql/error.log
#慢查询日志设置
slow_query_log=1
slow_query_log_file=/var/log/mysql/mysql-slow.log
long_query_time=2
#解决占用内存高的问题
performance_schema_max_table_instances=400
table_definition_cache=400
table_open_cache=256
performance_schema=off
#远程可以访问
bind_address=0.0.0.0
[mysqld_safe]
log-error=/var/log/mysql/error.log
pid-file=/var/run/mysqld/mysqld.pid
尝试过的解决方法
使用了pmap查询了内存映射信息(我删除了一些内容,太多了)
[root@ecm-dgbg0m weifuyun]# cat memmysql2.txt
2796674: mysqld
Address Perm Offset Device Inode Size Rss Pss Referenced Anonymous LazyFree ShmemPmdMapped Shared_Hugetlb Private_Hugetlb Swap SwapPss Locked THPeligible Mapping
00400000 r-xp 00000000 fd:01 35025999 22460 11544 11544 11544 0 0 0 0 0 0 0 0 0 /usr/sbin/mysqld
01bee000 r--p 015ee000 fd:01 35025999 948 540 540 540 436 0 0 0 0 0 0 0 0 /usr/sbin/mysqld
01cdb000 rw-p 016db000 fd:01 35025999 692 432 432 432 164 0 0 0 0 0 0 0 0 /usr/sbin/mysqld
01d88000 rw-p 00000000 00:00 0 768 616 616 616 616 0 0 0 0 0 0 0 1
02235000 rw-p 00000000 00:00 0 116944 115896 115896 115896 115896 0 0 0 0 0 0 0 1 [heap]
7f034c000000 rw-p 00000000 00:00 0 132 4 4 4 4 0 0 0 0 0 0 0 1
7f034c021000 ---p 00000000 00:00 0 65404 0 0 0 0 0 0 0 0 0 0 0 1
7f0350000000 rw-p 00000000 00:00 0 132 4 4 4 4 0 0 0 0 0 0 0 1
7f0350021000 ---p 00000000 00:00 0 65404 0 0 0 0 0 0 0 0 0 0 0 1
7f0354000000 rw-p 00000000 00:00 0 144 32 32 32 32 0 0 0 0 0 0 0 1
7f0354024000 ---p 00000000 00:00 0 65392 0 0 0 0 0 0 0 0 0 0 0 1
7f0358000000 rw-p 00000000 00:00 0 132 28 28 28 28 0 0 0 0 0 0 0 1
7f0358021000 ---p 00000000 00:00 0 65404 0 0 0 0 0 0 0 0 0 0 0 1
7f035c000000 rw-p 00000000 00:00 0 144 32 32 32 32 0 0 0 0 0 0 0 1
7f035c024000 ---p 00000000 00:00 0 65392 0 0 0 0 0 0 0 0 0 0 0 1
7f0360000000 rw-p 00000000 00:00 0 144 32 32 32 32 0 0 0 0 0 0 0 1
7f0360024000 ---p 00000000 00:00 0 65392 0 0 0 0 0 0 0 0 0 0 0 1
7f0364000000 rw-p 00000000 00:00 0 132 36 36 36 36 0 0 0 0 0 0 0 1
7f0364021000 ---p 00000000 00:00 0 65404 0 0 0 0 0 0 0 0 0 0 0 1
7f0368df0000 ---p 00000000 00:00 0 4 0 0 0 0 0 0 0 0 0 0 0 1
7f0368df1000 rw-p 00000000 00:00 0 8192 8 8 8 8 0 0 0 0 0 0 0 1
7f03695f1000 ---p 00000000 00:00 0 4 0 0 0 0 0 0 0 0 0 0 0 1
7f03695f2000 rw-p 00000000 00:00 0 8192 8 8 8 8 0 0 0 0 0 0 0 1
7f0369df2000 ---p 00000000 00:00 0 4 0 0 0 0 0 0 0 0 0 0 0 1
7f0369df3000 rw-p 00000000 00:00 0 8192 8 8 8 8 0 0 0 0 0 0 0 1
7f036a5f3000 ---p 00000000 00:00 0 4 0 0 0 0 0 0 0 0 0 0 0 1
7f036a5f4000 rw-p 00000000 00:00 0 26672 20480 20480 20480 20480 0 0 0 0 0 0 0 1
7f036c000000 rw-p 00000000 00:00 0 132 4 4 4 4 0 0 0 0 0 0 0 1
7f036c021000 ---p 00000000 00:00 0 65404 0 0 0 0 0 0 0 0 0 0 0 1
7f0370576000 rw-p 00000000 00:00 0 2200 2120 2120 2120 2120 0 0 0 0 0 0 0 1
7f037079c000 ---p 00000000 00:00 0 4 0 0 0 0 0 0 0 0 0 0 0 1
7f037079d000 rw-p 00000000 00:00 0 8192 8 8 8 8 0 0 0 0 0 0 0 1
7f0370f9d000 ---p 00000000 00:00 0 4 0 0 0 0 0 0 0 0 0 0 0 1
7f0370f9e000 rw-p 00000000 00:00 0 8192 8 8 8 8 0 0 0 0 0 0 0 1
7f037179e000 ---p 00000000 00:00 0 4 0 0 0 0 0 0 0 0 0 0 0 1
7f037179f000 rw-p 00000000 00:00 0 8192 8 8 8 8 0 0 0 0 0 0 0 1
7f0371f9f000 ---p 00000000 00:00 0 4 0 0 0 0 0 0 0 0 0 0 0 1
7f0371fa0000 rw-p 00000000 00:00 0 8192 20 20 20 20 0 0 0 0 0 0 0 1
7f03727a0000 ---p 00000000 00:00 0 4 0 0 0 0 0 0 0 0 0 0 0 1
7f03727a1000 rw-p 00000000 00:00 0 8192 8 8 8 8 0 0 0 0 0 0 0 1
7f0372fa1000 ---p 00000000 00:00 0 4 0 0 0 0 0 0 0 0 0 0 0 1
7f0372fa2000 rw-p 00000000 00:00 0 8192 8 8 8 8 0 0 0 0 0 0 0 1
7f03737a2000 ---p 00000000 00:00 0 4 0 0 0 0 0 0 0 0 0 0 0 1
7f03737a3000 rw-p 00000000 00:00 0 8192 8 8 8 8 0 0 0 0 0 0 0 1
7f0373fa3000 ---p 00000000 00:00 0 4 0 0 0 0 0 0 0 0 0 0 0 1
7f0373fa4000 rw-p 00000000 00:00 0 8192 12 12 12 12 0 0 0 0 0 0 0 1
7f03747a4000 ---p 00000000 00:00 0 4 0 0 0 0 0 0 0 0 0 0 0 1
7f03747a5000 rw-p 00000000 00:00 0 8192 8 8 8 8 0 0 0 0 0 0 0 1
7f0374fa5000 ---p 00000000 00:00 0 4 0 0 0 0 0 0 0 0 0 0 0 1
7f0374fa6000 rw-p 00000000 00:00 0 8192 8 8 8 8 0 0 0 0 0 0 0 1
7f03757a6000 ---p 00000000 00:00 0 4 0 0 0 0 0 0 0 0 0 0 0 1
7f03757a7000 rw-p 00000000 00:00 0 8192 8 8 8 8 0 0 0 0 0 0 0 1
7f0375fa7000 ---p 00000000 00:00 0 4 0 0 0 0 0 0 0 0 0 0 0 1
7f0375fa8000 rw-p 00000000 00:00 0 8192 8 8 8 8 0 0 0 0 0 0 0 1
7f03767a8000 ---p 00000000 00:00 0 4 0 0 0 0 0 0 0 0 0 0 0 1
7f03767a9000 rw-p 00000000 00:00 0 8192 8 8 8 8 0 0 0 0 0 0 0 1
7f0376fa9000 ---p 00000000 00:00 0 4 0 0 0 0 0 0 0 0 0 0 0 1
7f0376faa000 rw-p 00000000 00:00 0 40052 32848 32848 32848 32848 0 0 0 0 0 0 0 1
7f037d8f6000 rw-p 00000000 00:00 0 4594756 241420 241420 241420 241420 0 0 0 0 0 0 0 1
7f0496007000 ---p 00000000 00:00 0 4 0 0 0 0 0 0 0 0 0 0 0 1
7f0496008000 rw-p 00000000 00:00 0 8192 8 8 8 8 0 0 0 0 0 0 0 1
7f0496808000 r-xp 00000000 fd:01 36738535 48 48 48 48 0 0 0 0 0 0 0 0 0 /usr/lib64/libnss_files-2.17.so
7f0496814000 ---p 0000c000 fd:01 36738535 2044 0 0 0 0 0 0 0 0 0 0 0 0 /usr/lib64/libnss_files-2.17.so
7f0496a13000 r--p 0000b000 fd:01 36738535 4 4 4 4 4 0 0 0 0 0 0 0 0 /usr/lib64/libnss_files-2.17.so
7f0496a14000 rw-p 0000c000 fd:01 36738535 4 4 4 4 4 0 0 0 0 0 0 0 0 /usr/lib64/libnss_files-2.17.so
7f0496a15000 rw-p 00000000 00:00 0 16777240 16777216 16777216 16775904 16777216 0 0 0 0 0 0 0 1
7ffd235bc000 r--p 00000000 00:00 0 12 0 0 0 0 0 0 0 0 0 0 0 0 [vvar]
7ffd235bf000 r-xp 00000000 00:00 0 8 4 0 4 0 0 0 0 0 0 0 0 0 [vdso]
ffffffffff600000 r-xp 00000000 00:00 0 4 0 0 0 0 0 0 0 0 0 0 0 0 [vsyscall]
======== ======== ======== ========== ========= ======== ============== ============== =============== ==== ======= ====== ===========
22373384 17211932 17211928 17210620 17194096 0 0 0 0 0 0 0 89 KB
我想要达到的结果
怎么解决这个问题呢?