fan-yuan

mysql数据库使用sql查询数据库大小及表大小

网上查了很多资料,最后发现一个可行的,分享如下:

 

数据库大小查询:

select concat(round(sum(DATA_LENGTH/1024/1024),2),\'M\') from information_schema.TABLES where TABLE_SCHEMA=\'数据库名称\';

表大小查询:
SELECT concat(round(sum(DATA_LENGTH/1024/1024),2),\'M\') FROM information_schema.TABLES where TABLE_SCHEMA=\'数据库名称\' and table_name = \'表名称\';

 

 

查看指定数据库的大小,比如说:数据库apoyl
select concat(round(sum(DATA_LENGTH/1024/1024),2),\'MB\') as data from TABLES where table_schema=\'apoyl\';

查看指定数据库的表的大小,比如说:数据库apoyl 中apoyl_test表
select concat(round(sum(DATA_LENGTH/1024/1024),2),\'MB\') as data from TABLES where table_schema=\'apoyl\' and table_name=\'apoyl_test\';






查询每个表的数据量
select table_name,table_rows from tables where TABLE_SCHEMA = \'XXX\' order by table_rows desc;

分类:

技术点:

相关文章: