Documentation Home
MySQL 5.7 Reference Manual
Related Documentation Download this Manual
PDF (US Ltr) - 37.8Mb
PDF (A4) - 37.8Mb
PDF (RPM) - 36.4Mb
HTML Download (TGZ) - 9.9Mb
HTML Download (Zip) - 9.9Mb
HTML Download (RPM) - 8.6Mb
Man Pages (TGZ) - 209.5Kb
Man Pages (Zip) - 318.7Kb
Info (Gzip) - 3.5Mb
Info (Zip) - 3.5Mb
Excerpts from this Manual myisamchk Repair Options

myisamchk supports the following options for table repair operations (operations performed when an option such as --recover or --safe-recover is given):

  • --backup, -B

    Make a backup of the .MYD file as file_name-time.BAK

  • --character-sets-dir=dir_name

    The directory where character sets are installed. See Section 10.14, “Character Set Configuration”.

  • --correct-checksum

    Correct the checksum information for the table.

  • --data-file-length=len, -D len

    The maximum length of the data file (when re-creating data file when it is full).

  • --extend-check, -e

    Do a repair that tries to recover every possible row from the data file. Normally, this also finds a lot of garbage rows. Do not use this option unless you are desperate.

    See also the description of this option under table checking options.

    For a description of the output format, see Section, “Obtaining Table Information with myisamchk”.

  • --force, -f

    Overwrite old intermediate files (files with names like tbl_name.TMD) instead of aborting.

  • --keys-used=val, -k val

    For myisamchk, the option value is a bit value that indicates which indexes to update. Each binary bit of the option value corresponds to a table index, where the first index is bit 0. An option value of 0 disables updates to all indexes, which can be used to get faster inserts. Deactivated indexes can be reactivated by using myisamchk -r.

  • --no-symlinks, -l

    Do not follow symbolic links. Normally myisamchk repairs the table that a symlink points to. This option does not exist as of MySQL 4.0 because versions from 4.0 on do not remove symlinks during repair operations.

  • --max-record-length=len

    Skip rows larger than the given length if myisamchk cannot allocate memory to hold them.

  • --parallel-recover, -p

    Use the same technique as -r and -n, but create all the keys in parallel, using different threads. This is beta-quality code. Use at your own risk!

  • --quick, -q

    Achieve a faster repair by modifying only the index file, not the data file. You can specify this option twice to force myisamchk to modify the original data file in case of duplicate keys.

  • --recover, -r

    Do a repair that can fix almost any problem except unique keys that are not unique (which is an extremely unlikely error with MyISAM tables). If you want to recover a table, this is the option to try first. You should try --safe-recover only if myisamchk reports that the table cannot be recovered using --recover. (In the unlikely case that --recover fails, the data file remains intact.)

    If you have lots of memory, you should increase the value of myisam_sort_buffer_size.

  • --safe-recover, -o

    Do a repair using an old recovery method that reads through all rows in order and updates all index trees based on the rows found. This is an order of magnitude slower than --recover, but can handle a couple of very unlikely cases that --recover cannot. This recovery method also uses much less disk space than --recover. Normally, you should repair first using --recover, and then with --safe-recover only if --recover fails.

    If you have lots of memory, you should increase the value of key_buffer_size.

  • --set-collation=name

    Specify the collation to use for sorting table indexes. The character set name is implied by the first part of the collation name.

  • --sort-recover, -n

    Force myisamchk to use sorting to resolve the keys even if the temporary files would be very large.

  • --tmpdir=dir_name, -t dir_name

    The path of the directory to be used for storing temporary files. If this is not set, myisamchk uses the value of the TMPDIR environment variable. --tmpdir can be set to a list of directory paths that are used successively in round-robin fashion for creating temporary files. The separator character between directory names is the colon (:) on Unix and the semicolon (;) on Windows.

  • --unpack, -u

    Unpack a table that was packed with myisampack.

User Comments
  Posted by on November 18, 2003
This information doesn't cover what to do when myisamchk reports the following error:

myisamchk: error: '<table>' doesn't have a correct index definition. You need to recreate it before you can do a repair
  Posted by Tristan Bailey on June 29, 2004
This is what i used after I got the error:
"doesn't have a correct index definition. You need to recreate it before you can do a repair"

Login to command line mysql

mysql> CHECK TABLE stats;
| Table | Op | Msg_type | Msg_text |
| NEW.stats | check | warning | Table is marked as crashed |
| NEW.stats | check | error | Wrong bytesec: 0-0-0 at linkstart: 1204660 |
| NEW.stats | check | error | Corrupt |
3 rows in set (0.15 sec)

mysql> REPAIR TABLE stats;
| Table | Op | Msg_type | Msg_text |
| NEW.stats | repair | info | Wrong bytesec: 0-0-0 at 1204660; Skipped |
| NEW.stats | repair | warning | Number of rows changed from 10517 to 10487 |
| NEW.stats | repair | status | OK |
3 rows in set (0.22 sec)

Thanks to a google search I found this tip form Kevin W. Paulisse on "it appears that this error code is associated with a crash of the MySQL database, where the table (in this case, the search table) is marked as needing repair."

Now the table is up and running again, with all the data
  Posted by on June 7, 2006
Under the --keys-used=val option it should be noted that doing a myisamchk -r will not reactivate the keys until after a mysqladmin flush-tables has been executed.
  Posted by Brian Sperlongano on January 25, 2008
If you're trying to recover a HUGE table (10-100 million or more records) for which the .MYI file has become lost, here's one way to do it more quickly:

1. Run REPAIR TABLE ... USE_FRM, but kill it as soon as the .MYI is created

2. Stop any running copy of mysqld

3. Run myisamchk using one of the recover options
  Posted by Humberto Silva on January 20, 2010
If you're dealing with the error:

Incorrect key file for table '[...].MYI'; try to repair it

After having run out of space on disk, make sure you have the following:

1. Enough free space left on the machine
2. Run the repair: myisamchk -r [...].MYI
3. Restart mysqld (this could/should be done before the repair and, in my case, was needed so that the mysqld "knew" it had more free space to work)

Humberto Silva
Sign Up Login You must be logged in to post a comment.