#查看总的空间大小  默认单位是字节  除1024为K,除1048576为M 

 SELECT sum(DATA_LENGTH)+sum(INDEX_LENGTH) FROM information_schema.TABLES where TABLE_SCHEMA='boc-samsung'; 


 #查看某表占的空间大小 

 SELECT DATA_LENGTH FROM information_schema.TABLES WHERE TABLE_SCHEMA='boc-samsung' AND TABLE_NAME='sp_interface_packet' 


 #将所有数据库按照空间占用大小进行排序显示 

 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; 


 #将某数据库中所有的表按照空间大小进行排序 

 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 = 'boc-samsung' 

 group by TABLE_NAME 
order by data_length desc;

如果想知道MySQL数据库中每个表占用的空间、表记录的行数的话,可以打开MySQL的 information_schema 数据库。在该库中有一个 TABLES 表,这个表主要字段分别是:

TABLE_SCHEMA : 数据库名
TABLE_NAME:表名
ENGINE:所使用的存储引擎
TABLES_ROWS:记录数
DATA_LENGTH:数据大小
INDEX_LENGTH:索引大小