O'Reilly logo

Managing & Using MySQL, 2nd Edition by Hugh E. Williams, Randy Yarger, George Reese, Tim King

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required