Go to the previous topic.    Go to the next topic.

Performing table maintenance

Table maintenance operations are advanced functions. You should not use them without first reading and understanding the MySQL documentation.

Checking

Used to determine if a table contains errors; it runs a 'myisamchk -m' on 'MyISAM' and 'InnoDB' files from within MySQL. For `MyISAM' tables the key statistics are updated. You can get many rows of information for each checked table. The last row will be of `Msg_type status' and should normally be `OK'. If you don't get `OK', or `Not checked' you should run a repair of the table.

Analyzing

Used to analyze and store the key distribution for the table. During the analysis, the table is locked with a read lock. This works on `MyISAM' and `BDB' tables and is equivalent to running `myisamchk -a' on the table. MySQL uses the stored key distribution to decide in which order tables should be joined when one does a join on something other than a constant.

Repairing

Used to fix a table that you suspect may have been corrupted. Executing this operation returns a message describing whether a repair was warranted, and what exactly the problem was. Do not attempt to repair a table without first checking it.

Optimizing is used to reclaim unused space and defragment the data file. OPTIMIZE TABLE' works only on `MyISAM' and `BDB' tables. For `BDB' tables, `OPTIMIZE TABLE' is mapped to `ANALYZE TABLE'.

Flushing

Used to clear some of the internal caches MySQL uses. The flush commands include actions against: HOSTS, DES_KEY_FILE, LOGS, PRIVILEGES, QUERY CACHE, and TABLES. You can run these commands through the mysqladmin utility using `flush-hosts', `flush-logs', `reload', or `flush-tables' commands.