设为首页 加入收藏

TOP

统计mysql数据库、表大小(一)
2015-11-21 01:28:09 来源: 作者: 【 】 浏览:0
Tags:统计 mysql 数据库 大小
1. 查看该 数据库实例下所有库大小,得到的结果是以MB为单位
?
mysql> select table_schema,sum(data_length)/1024/1024 as data_length,sum(index_length)/1024/1024 \
as index_length,sum(data_length+index_length)/1024/1024 as sum from information_schema.tables;
+--------------------+---------------+--------------+---------------+
| table_schema       | data_length   | index_length | sum           |
+--------------------+---------------+--------------+---------------+
| information_schema | 2734.92757511 |  86.27539063 | 2821.20296574 |
+--------------------+---------------+--------------+---------------+

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

mysql>  select table_schema, sum(data_length+index_length)/1024/1024 as total_mb, \
sum(data_length)/1024/1024 as data_mb, sum(index_length)/1024/1024 as index_mb, \
count(*) as tables, curdate() as today from information_schema.tables group by table_schema order by 2 desc;
+--------------------+---------------+---------------+-------------+--------+------------+
| table_schema       | total_mb      | data_mb       | index_mb    | tables | today      |
+--------------------+---------------+---------------+-------------+--------+------------+
| data_1234567890    | 2820.59610939 | 2734.39689064 | 86.19921875 |     65 | 2015-11-02 |
| mysql              |    0.60579967 |    0.53744030 |  0.06835938 |     14 | 2015-11-02 |
| information_schema |    0.00781250 |    0.00000000 |  0.00781250 |     35 | 2015-11-02 |
+--------------------+---------------+---------------+-------------+--------+------------+

3、查看单个库的大小

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 = 'erongtu_tyb2014'; 
+-----------+------------------+-----------+------------+
| data_size | max_data_size    | data_free | index_size |
+-----------+------------------+-----------+------------+
| 2734.40mb | 83483426815.99mb | 14.06mb   | 86.19mb    |
+-----------+------------------+-----------+------------+
4、查看单个表的状态
mysql> show table status from data_1234567890 where name = 'data_1234567890_ss' \G
*************************** 1. row ***************************
           Name: data_1234567890_ss
         Engine: InnoDB
        Version: 10
     Row_format: Compact
           Rows: 840065
 Avg_row_length: 477
    Data_length: 401473536
Max_data_length: 0
   Index_length: 0
      Data_free: 6291456
 Auto_increment: 882251
    Create_time: 2015-09-07 17:24:18
    Update_time: NULL
     Check_time: NULL
      Collation: utf8_general_ci
       Checksum: NULL
 Create_options:
        Comment:
1 row in set (0.00 sec)
5、查看单库下所有表的状态
mysql> select table_name, (data_length/1024/1024) as data_mb , (index_length/1024/1024) \
as index_mb, ((data_length+index_length)/1024/1024) as all_mb, table_rows \
from tables where table_schema = 'data_1234567890';
+---------------------------+---------------+-------------+---------------+------------+
| table_name                | data_mb       | index_mb    | all_mb        | table_rows |
+---------------------------+---------------+-------------+---------------+------------+
| ss_daccount               |    0.23437500 |  0.10937500 |    0.34375000 |       4481 |
| ss_da
首页 上一页 1 2 3 下一页 尾页 1/3/3
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇一些能体现个人水平的SQL语句 下一篇mysql配置

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: