Florin Chiş

MySQL snippets, tips and tricks

  • Home
  • MySQL Tips
  • Quiz time ?
  • MySQL Tools
  • About me
RSS

Repair (or optimize) all tables from a database

Posted on 23/12/2011 by admin
No commentsLeave a comment

This stored routime fetches all tables from database, then executes an operation of REPAIR (you could also use OPTIMIZE command also) for each one. It operates on tables in database in which procedure has been defined.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
CREATE PROCEDURE `tools_repair_all_tables`()
    LANGUAGE SQL
    SQL SECURITY INVOKER
BEGIN
    DECLARE endloop INT DEFAULT 0;
    DECLARE tableName char(100);
    DECLARE rCursor CURSOR FOR SELECT `TABLE_NAME` FROM `information_schema`.`TABLES` WHERE `TABLE_SCHEMA`=DATABASE();
    DECLARE CONTINUE HANDLER FOR SQLSTATE '02000' SET endloop=1;
    OPEN rCursor;
    FETCH rCursor INTO tableName;
    WHILE endloop = 0 DO
        SET @sql = CONCAT('REPAIR TABLE `', tableName, '` QUICK;');
        PREPARE statement FROM @sql;
        EXECUTE statement;
        FETCH rCursor INTO tableName;
    END WHILE;
    CLOSE rCursor;
END
Categories: Mysql stored routines | Tags: automatic, database, mysql, repair, script, tables

About admin

Born in 1985 in Baia Mare, Maramures county in Romania. Studied at North University of Baia Mare, and obtained bachelor degree in 2011 in Computational Mathematic Applied in Informatics.
View all posts by admin→
Test
Padding a string with a char to complete fixed length width

Lasă un răspuns Anulează răspuns

Adresa ta de email nu va fi publicată. Câmpurile necesare sunt marcate *

*

*


question razz sad evil exclaim smile redface biggrin surprised eek confused cool lol mad twisted rolleyes wink idea arrow neutral cry mrgreen

Poți folosi aceste etichete HTML și atribute: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

  • Search

  • Recent posts

    • Convert UTF8 diacritics to ASCII in MySQL for use in website links
    • Generate table with random text from dictionary
    • Test
    • Repair (or optimize) all tables from a database
    • Padding a string with a char to complete fixed length width
  • What about you ?

    Do you create stored routines in MySQL ?

    View Results

    Loading ... Loading ...
    • Polls Archive
  • Categories

    • General
    • MySQL small projects
    • Mysql stored routines
  • Newsletter

    Want to receive articles in your mailbox ?

  • Meteo

    meteoblue.com
  • Legături

    • Cosmin Roman blog
    • Romania Maps
  • Tags

    article automatic char conversion database dictionary fixed generate latin length link mysql padding procedure random repair script tables text translation utf8 word

    WP Cumulus Flash tag cloud by Roy Tanck requires Flash Player 9 or better.

  • Archive

    • decembrie 2011
  • New comments

    • Parteneri

      Bloguri, Bloggeri si Cititori
      Blogarama - The Blog Directory
    Mysql tips, tricks and tests. Proudly Powered by WordPress | Nest Theme by YChong