查询库占用的空间和索引占用的空间
查整个库的状态:
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';
查单表:
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';
查看数据库使用大小:
select concat(round(sum(data_length/1024/1024),2),’MB’) as data from information_schema.tables where table_schema=’DB_Name’ ;
查看表使用大小:
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’;
或者直接用:
SHOW TABLE STATUS;