引入

在工作中,需要查询表的占用的空间以及数据库占用的空间

查询语句

查询每个数据库占用的空间的大小

1
SELECT table_schema, concat(round(sum(DATA_LENGTH/1024/1024),2),'MB') as data FROM TABLES group by table_schema;

查询每个表占用空间的大小

1
SELECT table_name, concat(round(sum(DATA_LENGTH/1024/1024),2),'MB') as data FROM TABLES where table_schema="db name" group by table_name;

所有库和表的大小

1
SELECT table_schema, table_name, concat(round(sum(DATA_LENGTH/1024/1024),2),'MB') as data FROM TABLES group by table_schema, table_name;