最近做项目用到mysql数据库,需要考虑1000多个用户的表大概会占用磁盘空间的大小,于是上网查询了一些资料,发现确实很好用,决定写下来。
个人只需要两个:
1>查询所有的数据库占用磁盘空间大小的sql语句:
select TABLE_SCHEMA, concat(truncate(sum(data_length)/1024/1024,2),' MB') as data_size,
concat(truncate(sum(index_length)/1024/1024,2),'MB') as index_size
from information_schema.tables
group by TABLE_SCHEMA
order by data_length desc;
2>查询单个数据库占用磁盘空间大小的sql语句:
select TABLE_NAME, concat(truncate(data_length/1024/1024,2),' MB') as data_size,
concat(truncate(index_length/1024/1024,2),' MB') as index_size
from information_schema.tables where TABLE_SCHEMA = 'database'
group by TABLE_NAME
order by data_length desc;
注:database为所查询的数据库的名称