Chinaunix首页 | 论坛 | 博客
  • 博客访问: 568817
  • 博文数量: 86
  • 博客积分: 2581
  • 博客等级: 少校
  • 技术积分: 793
  • 用 户 组: 普通用户
  • 注册时间: 2009-01-05 20:09
文章分类

全部博文(86)

文章存档

2009年(86)

我的朋友

分类: Mysql/postgreSQL

2009-09-12 11:17:26

Calculate index sizes

mysql> SELECT CONCAT(ROUND(SUM(index_length)/(1024*1024*1024), 2), ' GB') AS 'Total Index Size'
FROM information_schema.TABLES WHERE table_schema LIKE 'database';

+------------------+
| Total Index Size |
+------------------+
| 1.70 GB |
+------------------+
1 row in set (1.60 sec)


To calculate the total size of the data in the database

mysql> SELECT CONCAT(ROUND(SUM(data_length)/(1024*1024*1024), 2), ' GB') AS 'Total Data Size'
FROM information_schema.TABLES WHERE table_schema LIKE 'database';

+-----------------+
| Total Data Size |
+-----------------+
| 3.01 GB |
+-----------------+
1 row in set (1.35 sec)



An overall analysis of entire database on a per table basis

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


Just replace database with the partial name of your database you need to analyze. Yes, I know, those wonderful tools contains mk-find which can do the same thing, but then you won't learn about the information_schema database!!
MySQL DBA & Programming Blog by Mark Schoonover
阅读(5051) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~