Diamond Notes

Just another WordPress weblog

Tip of the Day — Repairing Tables — Part I

Sometimes things go bump in the night and break. There are various ways to fix tables when this happens. From the mysql command line you can do the following:

> check table table_name;

This does a check of the table structure and contents. It works on both MyISAM and InnoDB tables.

> repair table table_name;

This will correct corrupted tables. It only works for MyISAM tables.

> analyze table table_name;

This updates information that the server stores about the tables. This information is used by the server optimizer when determining the best choice for query execution. This will work for both InnoDB and MyISAM.

> optimize table table_name;

The optimize table command will compact and optimize a MyISAM table by creating a new copy of the table on the filesystem. While it is doing this it updates index statistics, and sorts the index pages themselves if necessary. optimize table will work for InnoDB but simply maps to an alter table command which performs the same essential operations.

1 Comment so far

  1. Tonny de Groot April 2nd, 2008 7:00 am

    Is it possible to optimize while online?
    i got a 120Gb Table i wish to make smaller.

    First i thought deleting obsolete rows and mysql will write at the beginning of the file rather then at the end. i was wrong in this case.

    so is it possible?

Leave a reply