mysql计算数据库容量大小

在Mysql中会有一个默认的数据库:information_schema,里面有一个Tables表记录了所有表的信息。使用该表来看数据库所占空间大小的代码如下:

如果要查某个库占用多少可以用下列命令:

USE information_schema;


比如查看数据库home的大小

select concat(round(sum(data_length/1024/1024),2),'MB') as data from tables where table_schema='home';

查看指定数据库的某个表的大小
比如查看数据库home中 members 表的大小

select concat(round(sum(data_length/1024/1024),2),'MB') as data from tables where table_schema='home' and table_name='members';