背景:现在大量的MySQL服务迁移到云上了,所以当发生空间占用的时候,分析哪个表占用较多就很麻烦,如果快速锁定元凶呢?
方案
一句话锁定元凶
select
table_schema as ‘数据库名称‘,
sum(table_rows) as ‘记录总数‘,
sum(truncate(data_length/1024/1024, 2)) as ‘数据容量(MB)‘,
sum(truncate(index_length/1024/1024, 2)) as ‘索引容量(MB)‘
from information_schema.tables
group by table_schema
order by sum(data_length) desc, sum(index_length) desc;
提取出来的数据一目了然,好好看看如何修理大表吧!