Repairing a Table

If the check reported errors on a table, you can try to repair them.

If you are using myisamchk or isamchk, make sure your MySQL server is not running when you attempt the repair. Also, it is a good idea to back up the data files before attempting a repair operation in case something goes haywire.

With myisamchk/isamchk, you should first try the --recover option:

$ isamchk  --recover table1.ISM
- recovering ISAM-table 'table1.ISM'
Data records: 3
$ myisamchk  --recover table2.MYI
- recovering (with keycache) MyISAM-table 'table2.MYI'
Data records: 2

If this fails for some reason, you can try --safe-recover , a slower recovery method that can fix some errors --recover cannot.

$ isamchk  --safe-recover table1.ISM
- recovering ISAM-table 'table1.ISM'
Data records: 3
$ myisamchk  --safe-recover table2.MYI
- recovering (with keycache) MyISAM-table 'table2.MYI'
Data records: 2

With mysqlcheck, your only recovery option is --repair .

$ mysqlcheck  --repair test table2
test.table2                                        OK

If these operations fail, your only remaining option is to restore the table from your backups and binary logs. See Section 4.4 and Section 4.5 for more information.

Get Managing & Using MySQL, 2nd Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.