mysql查看库、表占用存储空间大小

http://blog.csdn.net/bzfys/article/details/55252962

1. 查看该数据库实例下所有库大小,得到的结果是以MB为单位

1 <span class="keylink">mysql</span>> select table_schema,sum(data_length)/1024/1024 as data_length,sum(index_length)/1024/1024 \  
2 as index_length,sum(data_length+index_length)/1024/1024 as sum from information_schema.tables;  

 

2、查看该实例下各个库大小

1 mysql>  select table_schema, sum(data_length+index_length)/1024/1024 as total_mb,   
2 sum(data_length)/1024/1024 as data_mb, sum(index_length)/1024/1024 as index_mb,   
3 count(*) as tables, curdate() as today from information_schema.tables group by table_schema order by 2 desc;  

 

3、查看单个库的大小

1 mysql> select concat(truncate(sum(data_length)/1024/1024,2),'mb') as data_size,  
2 concat(truncate(sum(max_data_length)/1024/1024,2),'mb') as max_data_size,   
3 concat(truncate(sum(data_free)/1024/1024,2),'mb') as data_free,  
4 concat(truncate(sum(index_length)/1024/1024,2),'mb') as index_size 
5  from information_schema.tables where table_schema = 'schema_name';   

 

4、查看单个表的状态

1 mysql> show table status from data_1234567890 where name = 'data_1234567890_ss' \G  

 

5、查看单库下所有表的状态

1 mysql> select table_name, (data_length/1024/1024) as data_mb , (index_length/1024/1024)   
2 as index_mb, ((data_length+index_length)/1024/1024) as all_mb, table_rows   
3 from information_schema.tables where table_schema = 'schema_name';  

 

posted @ 2019-08-07 10:45  xiaojinniu425  阅读(8810)  评论(1编辑  收藏  举报