PDF (A4) - 43.4Mb
Man Pages (TGZ) - 297.3Kb
Man Pages (Zip) - 402.5Kb
Info (Gzip) - 4.3Mb
Info (Zip) - 4.3Mb
MySQL Globalization
MySQL Information Schema
MySQL Installation Guide
Security in MySQL
Starting and Stopping MySQL
MySQL and Linux/Unix
MySQL and Windows
MySQL and macOS
MySQL and Solaris
Building MySQL from Source
MySQL Restrictions and Limitations
MySQL Partitioning
MySQL Tutorial
MySQL Performance Schema
MySQL Replication
Using the MySQL Yum Repository
MySQL NDB Cluster 8.0
REPAIR [NO_WRITE_TO_BINLOG | LOCAL] TABLEtbl_name [,tbl_name] ... [QUICK] [EXTENDED] [USE_FRM]REPAIR TABLE repairs a possibly corrupted table, for certain storage engines only.
This statement requiresSELECT andINSERT privileges for the table.
Although normally you should never have to runREPAIR TABLE, if disaster strikes, this statement is very likely to get back all your data from aMyISAM table. If your tables become corrupted often, try to find the reason for it, to eliminate the need to useREPAIR TABLE. SeeSection B.3.3.3, “What to Do If MySQL Keeps Crashing”, andSection 18.2.4, “MyISAM Table Problems”.
REPAIR TABLE checks the table to see whether an upgrade is required. If so, it performs the upgrade, following the same rules asCHECK TABLE ... FOR UPGRADE. SeeSection 15.7.3.2, “CHECK TABLE Statement”, for more information.
Make a backup of a table before performing a table repair operation; under some circumstances the operation might cause data loss. Possible causes include but are not limited to file system errors. SeeChapter 9,Backup and Recovery.
If the server exits during a
REPAIR TABLEoperation, it is essential after restarting it that you immediately execute anotherREPAIR TABLEstatement for the table before performing any other operations on it. In the worst case, you might have a new clean index file without information about the data file, and then the next operation you perform could overwrite the data file. This is an unlikely but possible scenario that underscores the value of making a backup first.In the event that a table on the source becomes corrupted and you run
REPAIR TABLEon it, any resulting changes to the original table arenot propagated to replicas.
REPAIR TABLE works forMyISAM,ARCHIVE, andCSV tables. ForMyISAM tables, it has the same effect asmyisamchk --recovertbl_name by default. This statement does not work with views.
REPAIR TABLE is supported for partitioned tables. However, theUSE_FRM option cannot be used with this statement on a partitioned table.
You can useALTER TABLE ... REPAIR PARTITION to repair one or more partitions; for more information, seeSection 15.1.9, “ALTER TABLE Statement”, andSection 26.3.4, “Maintenance of Partitions”.
NO_WRITE_TO_BINLOGorLOCALBy default, the server writes
REPAIR TABLEstatements to the binary log so that they replicate to replicas. To suppress logging, specify the optionalNO_WRITE_TO_BINLOGkeyword or its aliasLOCAL.QUICKIf you use the
QUICKoption,REPAIR TABLEtries to repair only the index file, and not the data file. This type of repair is like that done bymyisamchk --recover --quick.EXTENDEDIf you use the
EXTENDEDoption, MySQL creates the index row by row instead of creating one index at a time with sorting. This type of repair is like that done bymyisamchk --safe-recover.USE_FRMThe
USE_FRMoption is available for use if the.MYIindex file is missing or if its header is corrupted. This option tells MySQL not to trust the information in the.MYIfile header and to re-create it using information from the data dictionary. This kind of repair cannot be done withmyisamchk.CautionUse the
USE_FRMoptiononly if you cannot use regularREPAIRmodes. Telling the server to ignore the.MYIfile makes important table metadata stored in the.MYIunavailable to the repair process, which can have deleterious consequences:The current
AUTO_INCREMENTvalue is lost.The link to deleted records in the table is lost, which means that free space for deleted records remains unoccupied thereafter.
The
.MYIheader indicates whether the table is compressed. If the server ignores this information, it cannot tell that a table is compressed and repair can cause change or loss of table contents. This means thatUSE_FRMshould not be used with compressed tables. That should not be necessary, anyway: Compressed tables are read only, so they should not become corrupt.
If you use
USE_FRMfor a table that was created by a different version of the MySQL server than the one you are currently running,REPAIR TABLEdoes not attempt to repair the table. In this case, the result set returned byREPAIR TABLEcontains a line with aMsg_typevalue oferrorand aMsg_textvalue ofFailed repairing incompatible .FRM file.If
USE_FRMis used,REPAIR TABLEdoes not check the table to see whether an upgrade is required.
REPAIR TABLE returns a result set with the columns shown in the following table.
| Column | Value |
|---|---|
Table | The table name |
Op | Alwaysrepair |
Msg_type | status,error,info,note, orwarning |
Msg_text | An informational message |
TheREPAIR TABLE statement might produce many rows of information for each repaired table. The last row has aMsg_type value ofstatus andMsg_test normally should beOK. For aMyISAM table, if you do not getOK, you should try repairing it withmyisamchk --safe-recover. (REPAIR TABLE does not implement all the options ofmyisamchk. Withmyisamchk --safe-recover, you can also use options thatREPAIR TABLE does not support, such as--max-record-length.)
REPAIR TABLE table catches and throws any errors that occur while copying table statistics from the old corrupted file to the newly created file. For example. if the user ID of the owner of the.MYD or.MYI file is different from the user ID of themysqld process,REPAIR TABLE generates a "cannot change ownership of the file" error unlessmysqld is started by theroot user.
REPAIR TABLE upgrades a table if it contains old temporal columns in pre-5.6.4 format (TIME,DATETIME, andTIMESTAMP columns without support for fractional seconds precision) and theavoid_temporal_upgrade system variable is disabled. Ifavoid_temporal_upgrade is enabled,REPAIR TABLE ignores the old temporal columns present in the table and does not upgrade them.
To upgrade tables that contain such temporal columns, disableavoid_temporal_upgrade before executingREPAIR TABLE.
You may be able to increaseREPAIR TABLE performance by setting certain system variables. SeeSection 10.6.3, “Optimizing REPAIR TABLE Statements”.
PDF (A4) - 43.4Mb
Man Pages (TGZ) - 297.3Kb
Man Pages (Zip) - 402.5Kb
Info (Gzip) - 4.3Mb
Info (Zip) - 4.3Mb
MySQL Globalization
MySQL Information Schema
MySQL Installation Guide
Security in MySQL
Starting and Stopping MySQL
MySQL and Linux/Unix
MySQL and Windows
MySQL and macOS
MySQL and Solaris
Building MySQL from Source
MySQL Restrictions and Limitations
MySQL Partitioning
MySQL Tutorial
MySQL Performance Schema
MySQL Replication
Using the MySQL Yum Repository
MySQL NDB Cluster 8.0