Previous Section  < Day Day Up >  Next Section

14.5 Checking and Repairing MyISAM Tables

MySQL provides two programs that help you check MyISAM tables for problems and repair damage if it occurs:

  • mysqlcheck is a client program that connects to the server and instructs it to perform table checking and repair operations.

  • myisamchk is a standalone utility that accesses MyISAM table files directly. Because myisamchk operates independently of the server, you must ensure that while you are using it, the server does not access the table's files.

Brief instructions for using mysqlcheck and myisamchk are given in the following discussion. More detailed information may be found in the "Core Study Guide."

To check or repair a table with mysqlcheck, use these commands:

shell> mysqlcheck db_name table_name

shell> mysqlcheck --repair db_name table_name

mysqlcheck acts as a command-line interface to the CHECK TABLE and REPAIR TABLE statements. You can issue these statements directly from within the mysql client or from other applications that send statements to the server. By using these statements, you can write your own administrative applications that perform table checking and repair operations.

A recommended table-checking strategy is to run mysqlcheck with no options. If any errors occur, run it again, first with the --repair and --quick options to attempt a quick repair. If that fails, run mysqlcheck with --repair for a normal repair, and then if necessary with --repair and --force.

To check or repair a table with myisamchk, first make sure that the server will not access the table. (One way to do this is to stop the server.) Then change location into the database directory of the database that contains the table and use the following commands:

shell> myisamchk db_name table_name

shell> myisamchk --recover db_name table_name

If a repair operation performed with --recover encounters problems that it cannot fix, try using the --safe-recover option. --safe-recover can fix some problems that --recover cannot.

An administrator who is responsible for server operation can instruct the server to check and repair tables automatically. To do this, use the --myisam-recover option. The option value can consist of a comma-separated list of one or more of the following values:

  • DEFAULT is the same as using no --myisam-recover option at all.

  • BACKUP tells the server to make a backup of any table that it must change.

  • FORCE causes table recovery to be performed even if it would cause loss of more than one row of data.

  • QUICK performs quick recovery: Tables that have no holes resulting from deletes or updates are skipped.

For example, to tell the server to perform a forced recovery but make a backup of any table it changes, you can put the following lines in an option file:



    Previous Section  < Day Day Up >  Next Section