Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2353762
  • 博文数量: 276
  • 博客积分: 5998
  • 博客等级: 大校
  • 技术积分: 5175
  • 用 户 组: 普通用户
  • 注册时间: 2010-12-24 14:43
文章分类

全部博文(276)

文章存档

2014年(25)

2013年(11)

2012年(69)

2011年(167)

2010年(4)

分类: Mysql/postgreSQL

2011-09-09 22:12:42

 

sql代码:perschema.sql

作用:

    1、统计库的大小,数据大小,索引大小,表的数量。

    2、按库,引擎,校验字符集分类并统计各种类型含有的表的数量

    3、统计指定库每个表大小,数据大小,索引大小,引擎,数据行的格式,表的行数,平均每行的长   度。

     4、统计含有text,blog大字段的表。

     5、统计每个表含有的大于255长度的varchar大字段,字段的最大长度。

     6、统计库中含有bigint字段且为auto_increment的表名,字段名字。

     7、统计库中含有的存储过程总数,视图总数,触发器总数。

  1. SELECT NOW(), VERSION();

  2. # Per Schema Queries

  3. SET @schema = IFNULL(@schema,DATABASE());

  4. # One Line Schema Summary
  5. SELECT table_schema,
  6.          SUM(data_length+index_length)/1024/1024 AS total_mb,
  7.          SUM(data_length)/1024/1024 AS data_mb,
  8.          SUM(index_length)/1024/1024 AS index_mb,
  9.          COUNT(*) AS tables,
  10.          CURDATE() AS today
  11. FROM information_schema.tables
  12. WHERE table_schema=@schema
  13. GROUP BY table_schema;

  14. # Schema Engine/Collation Summary
  15. SELECT table_schema,engine,table_collation,
  16.          COUNT(*) AS tables
  17. FROM information_schema.tables
  18. WHERE table_schema=@schema
  19. GROUP BY table_schema,engine,table_collation;


  20. # Schema Table Usage
  21. SELECT @schema as table_schema, CURDATE() AS today;
  22. SELECT if(length(table_name)>20,concat(left(table_name,18),'..'),table_name) AS table_name,
  23.          engine,row_format as format, table_rows, avg_row_length as avg_row,
  24.          round((data_length+index_length)/1024/1024,2) as total_mb,
  25.          round((data_length)/1024/1024,2) as data_mb,
  26.          round((index_length)/1024/1024,2) as index_mb
  27. FROM information_schema.tables
  28. WHERE table_schema=@schema
  29. ORDER BY 6 DESC;

  30. # Schema Table BLOB/TEXT Usage
  31. select table_schema,table_name,column_name,data_type
  32. from information_schema.columns
  33. where table_schema= @schema
  34. and ( data_type LIKE '%TEXT' OR data_type like '%BLOB');

  35. # Large varchars
  36. select table_schema,table_name,column_name,character_maximum_length from information_schema.columns where data_type='varchar' and character_maximum_length > 255 and table_schema = @schema;

  37. select table_schema,table_name,column_name,data_type,extra from information_schema.columns where data_type='bigint' and extra like '%auto_increment%' and table_schema = @schema;

  38. select 'routines',count(*) from information_schema.routines where routine_schema= @schema
  39. union
  40. select 'views',count(*) from information_schema.views where table_schema= @schema
  41. union
  42. select 'triggers',count(*) from information_schema.triggers where trigger_schema= @schema;

  43. set @schema = NULL;
阅读(963) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~