MySQueaL Resources

resources for mysql admins and developers who are squealing for help

More Resources

Main Doc Pages
Comments
MySQL columns: everywhere I look are tables and columns; life is filled with databases of information to be ordered and grouped. (Ca'Grande, Milan, Italy)

REPAIR TABLE Statement

Use this MySQL statement to repair corrupted MyISAM tables.

hits past month: 11 ;  last updated: may 4, 2009 - 2:34am ;  parent: MySQL Table & Server Administration Statements

Syntax

REPAIR [LOCAL|NO_WRITE_TO_BINLOG] TABLE
    table[, ...] [QUICK] [EXTENDED] [USE_FRM]

Explanation

Use this statement to repair corrupted MyISAM tables. Multiple tables may be given in a comma-separated list. To prevent this statement from recording its activities in the binary log file, give the NO_WRITE_TO_BINLOG keyword or its LOCAL alias. The QUICK keyword instructs MySQL to repair the table indexes only. The EXTENDED keyword rebuilds the indexes one row at a time. This option takes longer, but can be more effective, especially with rows containing duplicate keys.

Before running this statement, make a backup of the table. If a table continues to have problems, there may be other problems (e.g., filesystem problems) that you should consider.

Examples

Here is an example of this statement:

REPAIR TABLE systems QUICK EXTENDED;

+----------------------+--------+----------+----------+
| Table                | Op     | Msg_type | Msg_text |
+----------------------+--------+----------+----------+
| workrequests.systems | repair | status   | OK       |
+----------------------+--------+----------+----------+

In this example, the repair was successful. This is indicated by the OK in the Msg_text field. If it were unsuccessful, you could try the USE_FRM option with this statement. This option will create a new index file (.MYI) using the table schema file (.frm). It won't be able to determine the current value for AUTO_INCREMENT columns or for DELETE LINK, so it shouldn't be used unless the original .MYI file is lost. Incidentally, if the MySQL server dies while the REPAIR TABLE statement is running, you should run the statement again as soon as the server is back up, before running any other SQL statements.

Return to MySQL Table & Server Administration Statements page of our MySQL Documentation