mysql 查询库表磁盘占用

查整个库的状态:
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 table_name,
data_length / 1024 / 1024 AS data_size,
index_length / 1024 / 1024 AS index_size
FROM tables
order by data_size desc limit 20;

posted @ 2014-07-01 13:23  韩宏敏  阅读(259)  评论(0编辑  收藏  举报