943,929 Members | Top Members by Rank

Ad:
  • MySQL Discussion Thread
  • Unsolved
  • Views: 2239
  • MySQL RSS
Feb 4th, 2009
-1

Analyze all tables in a database?

Expand Post »
How do I analyze all tables in a database?
Similar Threads
Reputation Points: 10
Solved Threads: 1
Junior Poster in Training
desiguru is offline Offline
63 posts
since Aug 2006
Feb 5th, 2009
0

Re: Analyze all tables in a database?

You can do it by a sp or from Mysql Administrator
I generally do it from Sp

sql Syntax (Toggle Plain Text)
  1. DELIMITER $$
  2.  
  3. DROP PROCEDURE IF EXISTS `reports`.`SP_Mysql_Maintance_Plan_Optimize_Tables`$$
  4.  
  5. CREATE PROCEDURE `SP_Mysql_Maintance_Plan_Optimize_Tables`()
  6. BEGIN
  7. DECLARE l_loop_end INT DEFAULT 0;
  8. DECLARE IN_TABLE_SCHEMA VARCHAR(100);
  9. DECLARE IN_TABLE_NAME VARCHAR(100);
  10. DECLARE CUR1 CURSOR FOR
  11. SELECT TABLE_SCHEMA,TABLE_NAME FROM information_schema.TABLES
  12. WHERE TABLE_SCHEMA NOT IN ('TEST','information_schema');
  13. DECLARE continue HANDLER for sqlstate '02000' SET l_loop_end = 1;
  14. open CUR1;
  15. REPEAT
  16. FETCH cur1 INTO IN_TABLE_SCHEMA,IN_TABLE_NAME;
  17. if NOT l_loop_end THEN
  18. SELECT '' AS '';
  19. SELECT CONCAT('DATABASE NAME: ' ,IN_TABLE_SCHEMA,' TABLE NAME : ',IN_TABLE_NAME) AS '';
  20. SELECT CONCAT('START TIME: ',NOW()) as '';
  21. SET @qry = CONCAT('OPTIMIZE TABLE ', IN_TABLE_SCHEMA, '.',IN_TABLE_NAME);
  22. PREPARE stmt FROM @qry;
  23. EXECUTE stmt;
  24. DEALLOCATE PREPARE stmt;
  25. SELECT CONCAT('END TIME: ',NOW()) AS '';
  26. SELECT '' AS '';
  27. END if;
  28. until l_loop_end END REPEAT;
  29. close cur1;
  30. END$$
  31.  
  32. DELIMITER ;
Last edited by peter_budo; Feb 10th, 2009 at 8:30 am. Reason: Please use [code] instead of [quote] tag
Reputation Points: 22
Solved Threads: 9
Junior Poster in Training
varmadba is offline Offline
83 posts
since Jun 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in MySQL Forum Timeline: need help, please!
Next Thread in MySQL Forum Timeline: Mysql and php optimization please!!! :(





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC