Analyze all tables in a database?

Reply

Join Date: Aug 2006
Posts: 59
Reputation: desiguru is an unknown quantity at this point 
Solved Threads: 1
desiguru desiguru is offline Offline
Junior Poster in Training

Analyze all tables in a database?

 
0
  #1
Feb 4th, 2009
How do I analyze all tables in a database?
--
Share files up to 1Gb - FileOP.com
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 79
Reputation: varmadba is an unknown quantity at this point 
Solved Threads: 8
varmadba varmadba is offline Offline
Junior Poster in Training

Re: Analyze all tables in a database?

 
0
  #2
Feb 5th, 2009
You can do it by a sp or from Mysql Administrator
I generally do it from Sp

  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
:- Varma

We are Happy to inform launch of a new site with loads of database related information Site offers wide range of functionality Forums,Blogs,Articles,Editorials and much more
http://www.sqllibrarian.info/
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the MySQL Forum
Thread Tools Search this Thread



Tag cloud for MySQL
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC