【mysql监控】查看mysql库大小,表大小,索引大小

admin
admin 这家伙很懒,还没有设置简介...

0 人点赞了该文章 · 352 浏览

查看指定库的大小

select concat(round(sum(DATA_LENGTH/1024/1024),2),'MB') as data  from information_schema.TABLES where table_schema='mkey3gdb';

 

每个数据表使用

SELECT CONCAT(table_schema,'.',table_name) AS 'Table Name', CONCAT(ROUND(table_rows),'条') AS 'Number of Rows', CONCAT(ROUND(data_length/(1024*1024*1024),4),'G') AS 'Data Size', CONCAT(ROUND(index_length/(1024*1024*1024),4),'G') AS 'Index Size', CONCAT(ROUND((data_length+index_length)/(1024*1024*1024),4),'G') AS'Total'FROM information_schema.TABLES WHERE table_schema LIKE 'mkey3gdb';

 

 

 

占用表空间较大的数据表是mip_visit_log、mdp_logs、mip_logs这三个表

SELECT CONCAT(table_schema,'.',table_name) AS 'Table Name', CONCAT(ROUND(table_rows),'条') AS 'Number of Rows', CONCAT(ROUND(data_length/(1024*1024),4),'MB') AS 'Data Size',  CONCAT(ROUND((data_length+index_length)/(1024*1024),4),'MB') AS'Total'FROM information_schema.TABLES WHERE table_name='mdp_logs'  or table_name='mip_visit_log' or table_name='mip_logs';

 

SELECT CONCAT(table_schema,'.',table_name) AS 'Table Name', CONCAT(ROUND(table_rows),'条') AS 'Number of Rows', CONCAT(ROUND(data_length,4),'字节') AS 'Data Size',  CONCAT(ROUND((data_length+index_length)/(1024*1024),4),'MB') AS'Total'FROM information_schema.TABLES WHERE table_name='mip_visit_log';




查看所有库的大小
mysql> use information_schema;
Database changed
mysql> select concat(round(sum(DATA_LENGTH/1024/1024),2),'MB') as data  from TABLES;
+----------+
| data     |
+----------+
| 104.21MB |
+----------+
1 row in set (0.11 sec)

mysql> select concat(round(sum(DATA_LENGTH/1024/1024),2),'MB') as data  from information_schema.TABLES where table_schema='jishi';
+---------+
| data    |
+---------+
| 26.17MB |
+---------+
1 row in set (0.01 sec)
查看指定库的指定表的大小
mysql> select concat(round(sum(DATA_LENGTH/1024/1024),2),'MB') as data  from information_schema.TABLES where table_schema='jishi' and table_name='a_ya';
+--------+
| data   |
+--------+
| 0.02MB |
+--------+
1 row in set (0.00 sec)
查看指定库的索引大小
mysql> SELECT CONCAT(ROUND(SUM(index_length)/(1024*1024), 2), ' MB') AS 'Total Index Size' FROM information_schema.TABLES  WHERE table_schema = 'jishi'; 
+------------------+
| Total Index Size |
+------------------+
| 0.94 MB          |
+------------------+
1 row in set (0.01 sec)
查看指定库的指定表的索引大小
mysql> SELECT CONCAT(ROUND(SUM(index_length)/(1024*1024), 2), ' MB') AS 'Total Index Size' FROM information_schema.TABLES  WHERE table_schema = 'test' and table_name='a_yuser'; 
+------------------+
| Total Index Size |
+------------------+
| 21.84 MB         |
+------------------+
1 row in set (0.00 sec)
mysql> show create table test.a_yuser\G;
*************************** 1. row ***************************
       Table: a_yuser
Create Table: CREATE TABLE `a_yuser` (
  `email` varchar(60) NOT NULL DEFAULT '',
  `user_name` varchar(60) NOT NULL DEFAULT '',
  KEY `cc` (`email`(5)),
  KEY `ccb` (`user_name`(5)),
  KEY `ccbc` (`email`(5),`user_name`(5))
) ENGINE=MyISAM DEFAULT CHARSET=utf8
1 row in set (0.00 sec)
ERROR: 
No query specified
mysql> select count(*) from test.a_yuser;
+----------+
| count(*) |
+----------+
|  1073607 |
+----------+
1 row in set (0.00 sec)
mysql> 
查看一个库中的情况...
mysql>  SELECT CONCAT(table_schema,'.',table_name) AS 'Table Name', CONCAT(ROUND(table_rows/1000000,4),'M') AS 'Number of Rows', CONCAT(ROUND(data_length/(1024*1024*1024),4),'G') AS 'Data Size', CONCAT(ROUND(index_length/(1024*1024*1024),4),'G') AS 'Index Size', CONCAT(ROUND((data_length+index_length)/(1024*1024*1024),4),'G') AS'Total'FROM information_schema.TABLES WHERE table_schema LIKE 'test';
+---------------+----------------+-----------+------------+---------+
| Table Name    | Number of Rows | Data Size | Index Size | Total   |
+---------------+----------------+-----------+------------+---------+
| test.a_br     | 0.4625M        | 0.0259G   | 0.0171G    | 0.0431G |
| test.a_skuclr | 0.7099M        | 0.0660G   | 0.0259G    | 0.0919G |
| test.a_yuser  | 1.0736M        | 0.0497G   | 0.0213G    | 0.0710G |
| test.test     | 0.0000M        | 0.0000G   | 0.0000G    | 0.0000G |
+---------------+----------------+-----------+------------+---------+
4 rows in set (0.13 sec)
mysql> SELECT CONCAT(table_schema,'.',table_name) AS 'Table Name', CONCAT(ROUND(table_rows/1000000,4),'M') AS 'Number of Rows', CONCAT(ROUND(data_length/(1024*1024),4),'MB') AS 'Data Size',  CONCAT(ROUND((data_length+index_length)/(1024*1024),4),'MB') AS'Total'FROM information_schema.TABLES WHERE TABLE_NAME='mdp_logs';
+-------------------+----------------+-----------+----------+
| Table Name        | Number of Rows | Data Size | Total    |
+-------------------+----------------+-----------+----------+
| mkey3gdb.mdp_logs | 0.0002M        | 0.0928MB  | 0.0986MB |
+-------------------+----------------+-----------+----------+
1 row in set

mysql> SELECT CONCAT(table_schema,'.',table_name) AS 'Table Name', CONCAT(ROUND(table_rows/1000000,4),'M') AS 'Number of Rows', CONCAT(ROUND(data_length/(1024*1024),4),'MB') AS 'Data Size',  CONCAT(ROUND((data_length+index_length)/(1024*1024),4),'MB') AS'Total'FROM information_schema.TABLES WHERE table_name='mdp_logs'  or table_name='mip_visit_log' or table_name='mip_logs';
+------------------------+----------------+-----------+----------+
| Table Name             | Number of Rows | Data Size | Total    |
+------------------------+----------------+-----------+----------+
| mkey3gdb.mdp_logs      | 0.0002M        | 0.0928MB  | 0.0986MB |
| mkey3gdb.mip_logs      | 0.0000M        | 0.0000MB  | 0.0010MB |
| mkey3gdb.mip_visit_log | 0.0003M        | 0.0440MB  | 0.0498MB |
+------------------------+----------------+-----------+----------+
3 rows in set  

发布于 2015-12-08 12:33

免责声明:

本文由 admin 原创发布于 优势智云 ,著作权归作者所有。

登录一下,更多精彩内容等你发现,贡献精彩回答,参与评论互动

登录! 还没有账号?去注册

暂无评论

All Rights Reserved Powered BY WeCenter V4.0.3 © 2026 粤ICP备17102936号