Query library occupied space and index space occupied

Check the status of the entire library:

select concat(truncate(sum(data_length)/1024/1024,2),'MB') as data_size,
concat(truncate(sum(max_data_length)/1024/1024,2),'MB') as max_data_size,
concat(truncate(sum(data_free)/1024/1024,2),'MB') as data_free,
concat(truncate(sum(index_length)/1024/1024,2),'MB') as index_size
from information_schema.tables where TABLE_SCHEMA = 'databasename';
 
Check a single table:
select concat(truncate(sum(data_length)/1024/1024,2),'MB') as data_size,
concat(truncate(sum(max_data_length)/1024/1024,2),'MB') as max_data_size,
concat(truncate(sum(data_free)/1024/1024,2),'MB') as data_free,
concat(truncate(sum(index_length)/1024/1024,2),'MB') as index_size
from information_schema.tables where TABLE_NAME = 'tablename';
 
View the database size use:
select concat(round(sum(data_length/1024/1024),2),’MB’) as data from information_schema.tables where table_schema=’DB_Name’ ;
 
View table using Size:
select concat(round(sum(data_length/1024/1024),2),’MB’) as data from information_schema.tables where table_schema=’DB_Name’ and table_name=’Table_Name’;
 
Or directly: 
SHOW TABLE STATUS;
 
 

Guess you like

Origin www.cnblogs.com/Ghost-bird/p/11592004.html