问题:
发现docker容器mysql的内存使用高,达到9个G快满了。
开始按网上资料,查了以下二个方面,结果不是这二方面的问题,这里不再详述:
1)连接池占用内存情况
2)会话占用内存情况
最后,问题是MSQL表空间碎片过大的问题。
存在碎片的表查询
select concat('optimize table ',table_schema,'.',table_name,';'), data_free, engine from information_schema.tables where data_free>0 and engine !='MEMORY';
结果
找到碎片化最严重的表
SELECT table_schema, TABLE_NAME, concat(data_free/1024/1024, 'M') as data_free FROM `information_schema`.tables WHERE data_free > 3 * 1024 * 1024 AND ENGINE = 'innodb' ORDER BY data_free DESC
结果
MySQL 碎片的清除
optimize table point_history_data;
运行
最终结果,内存占用回到正常
SELECT table_schema, TABLE_NAME, concat(data_free/1024/1024, 'M') as data_free FROM `information_schema`.tables WHERE data_free > 3 * 1024 * 1024 AND ENGINE = 'innodb' ORDER BY data_free DESC
docker stats查看内存
参考
https://www.kongzid.com/archives/mysql4#1%E3%80%81mysql-%E7%A2%8E%E7%89%87%E4%BA%A7%E7%94%9F%E7%9A%84%E5%8E%9F%E5%9B%A0
标签:1024,占用,free,内存,MYSQL,table,data,schema From: https://www.cnblogs.com/chinatudou/p/17129406.html