MySQL 表占用空间排行

phpMyAdmin用多了不会手写SQL了吧

1
2
3
4
5
6
7
8
9
10
select t.TABLE_NAME
, t.TABLE_ROWS
, round(t.DATA_LENGTH/1024/1024/1024, 2) dataSpace
, round(t.INDEX_LENGTH/1024/1024/1024, 2) indexSpace
, round(sum((t.DATA_LENGTH + t.INDEX_LENGTH)/1024/1024/1024), 2) usedSpace
from information_schema.TABLES t
where t.TABLE_SCHEMA = '数据库名'
group by t.TABLE_NAME
order by usedSpace desc
limit N