Linux "myisamchk" Command Line Options and Examples
MyISAM table-maintenance utility

The myisamchk utility gets information about your database tables or checks, repairs, or optimizes them. myisamchk works with MyISAM tables (tables that have .MYD and .


Usage:

myisamchk [options] tbl_name ...




Command Line Options:

--help
Display a help message and exit. Options are grouped by type of operation.
myisamchk --help ...
--HELP
Display a help message and exit. Options are presented in a single list.
myisamchk --HELP ...
--debug
Write a debugging log. A typical debug_options string is d:t:o,file_name. The default is d:t:o,/tmp/myisamchk.trace.
myisamchk --debug ...
--defaults-extra-file
Read this option file after the global option file but (on Unix) before the user option file. If the file does not exist or isotherwise inaccessible, an error occurs. file_name is interpreted relative to the current directory if given as a relative pathname rather than a full path name.For additional information about this and other option-file options, see Section 4.2.2.3, “Command-Line Options that AffectOption-File Handling”.
myisamchk --defaults-extra-file ...
--defaults-file
Use only the given option file. If the file does not exist or is otherwise inaccessible, an error occurs. file_name isinterpreted relative to the current directory if given as a relative path name rather than a full path name.For additional information about this and other option-file options, see Section 4.2.2.3, “Command-Line Options that AffectOption-File Handling”.
myisamchk --defaults-file ...
--defaults-group-suffix
Read not only the usual option groups, but also groups with the usual names and a suffix of str. For example, myisamchk normallyreads the [myisamchk] group. If the --defaults-group-suffix=_other option is given, myisamchk also reads the [myisamchk_other]group.For additional information about this and other option-file options, see Section 4.2.2.3, “Command-Line Options that AffectOption-File Handling”.
myisamchk --defaults-group-suffix ...
--no-defaults
Do not read any option files. If program startup fails due to reading unknown options from an option file, --no-defaults can beused to prevent them from being read.The exception is that the .mylogin.cnf file, if it exists, is read in all cases. This permits passwords to be specified in asafer way than on the command line even when --no-defaults is used. (.mylogin.cnf is created by the mysql_config_editor utility.See mysql_config_editor(1).)For additional information about this and other option-file options, see Section 4.2.2.3, “Command-Line Options that AffectOption-File Handling”.
myisamchk --no-defaults ...
--print-defaults
Print the program name and all options that it gets from option files.For additional information about this and other option-file options, see Section 4.2.2.3, “Command-Line Options that AffectOption-File Handling”.
myisamchk --print-defaults ...
--silent
Silent mode. Write output only when errors occur. You can use -s twice (-ss) to make myisamchk very silent.
myisamchk --silent ...
--verbose
Verbose mode. Print more information about what the program does. This can be used with -d and -e. Use -v multiple times (-vv,
myisamchk --verbose ...
-vvv)
for even more output.
myisamchk -vvv) ...
--version
Display version information and exit.
myisamchk --version ...
--wait
Instead of terminating with an error if the table is locked, wait until the table is unlocked before continuing. If you arerunning mysqld with external locking disabled, the table can be locked only by another myisamchk command.You can also set the following variables by using --var_name=value syntax:┌───────────────────────┬───────────────────┐│Variable │ Default Value │├───────────────────────┼───────────────────┤│decode_bits │ 9 │├───────────────────────┼───────────────────┤│ft_max_word_len │ version-dependent │├───────────────────────┼───────────────────┤│ft_min_word_len │ 4 │├───────────────────────┼───────────────────┤│ft_stopword_file │ built-in list │├───────────────────────┼───────────────────┤│key_buffer_size │ 523264 │├───────────────────────┼───────────────────┤│myisam_block_size │ 1024 │├───────────────────────┼───────────────────┤│myisam_sort_key_blocks │ 16 │├───────────────────────┼───────────────────┤│read_buffer_size │ 262136 │├───────────────────────┼───────────────────┤│sort_buffer_size │ 2097144 │├───────────────────────┼───────────────────┤│sort_key_blocks │ 16 │├───────────────────────┼───────────────────┤│stats_method │ nulls_unequal │├───────────────────────┼───────────────────┤│write_buffer_size │ 262136 │└───────────────────────┴───────────────────┘The possible myisamchk variables and their default values can be examined with myisamchk --help:myisam_sort_buffer_size is used when the keys are repaired by sorting keys, which is the normal case when you use --recover.sort_buffer_size is a deprecated synonym for myisam_sort_buffer_size.key_buffer_size is used when you are checking the table with --extend-check or when the keys are repaired by inserting keys row byrow into the table (like when doing normal inserts). Repairing through the key buffer is used in the following cases:· You use --safe-recover.· The temporary files needed to sort the keys would be more than twice as big as when creating the key file directly. This is oftenthe case when you have large key values for CHAR, VARCHAR, or TEXT columns, because the sort operation needs to store thecomplete key values as it proceeds. If you have lots of temporary space and you can force myisamchk to repair by sorting, you canuse the --sort-recover option.Repairing through the key buffer takes much less disk space than using sorting, but is also much slower.If you want a faster repair, set the key_buffer_size and myisam_sort_buffer_size variables to about 25% of your available memory. Youcan set both variables to large values, because only one of them is used at a time.myisam_block_size is the size used for index blocks.stats_method influences how NULL values are treated for index statistics collection when the --analyze option is given. It acts likethe myisam_stats_method system variable. For more information, see the description of myisam_stats_method in Section 5.1.8, “ServerSystem Variables”, and Section 8.3.8, “InnoDB and MyISAM Index Statistics Collection”.ft_min_word_len and ft_max_word_len indicate the minimum and maximum word length for FULLTEXT indexes on MyISAM tables.ft_stopword_file names the stopword file. These need to be set under the following circumstances.If you use myisamchk to perform an operation that modifies table indexes (such as repair or analyze), the FULLTEXT indexes arerebuilt using the default full-text parameter values for minimum and maximum word length and the stopword file unless you specifyotherwise. This can result in queries failing.The problem occurs because these parameters are known only by the server. They are not stored in MyISAM index files. To avoid theproblem if you have modified the minimum or maximum word length or the stopword file in the server, specify the same ft_min_word_len,ft_max_word_len, and ft_stopword_file values to myisamchk that you use for mysqld. For example, if you have set the minimum wordlength to 3, you can repair a table with myisamchk like this:shell> myisamchk --recover --ft_min_word_len=3 tbl_name.MYITo ensure that myisamchk and the server use the same values for full-text parameters, you can place each one in both the [mysqld] and[myisamchk] sections of an option file:[mysqld]ft_min_word_len=3[myisamchk]ft_min_word_len=3An alternative to using myisamchk is to use the REPAIR TABLE, ANALYZE TABLE, OPTIMIZE TABLE, or ALTER TABLE. These statements areperformed by the server, which knows the proper full-text parameter values to use.MYISAMCHK CHECK OPTIONSmyisamchk supports the following options for table checking operations:
myisamchk --wait ...
--check
Check the table for errors. This is the default operation if you specify no option that selects an operation type explicitly.
myisamchk --check ...
--check-only-changed
Check only tables that have changed since the last check.
myisamchk --check-only-changed ...
--extend-check
Check the table very thoroughly. This is quite slow if the table has many indexes. This option should only be used in extremecases. Normally, myisamchk or myisamchk --medium-check should be able to determine whether there are any errors in the table.If you are using --extend-check and have plenty of memory, setting the key_buffer_size variable to a large value helps the repairoperation run faster.See also the description of this option under table repair options.For a description of the output format, see the section called “OBTAINING TABLE INFORMATION WITH MYISAMCHK”.
myisamchk --extend-check ...
--fast
Check only tables that haven't been closed properly.
myisamchk --fast ...
--force
Do a repair operation automatically if myisamchk finds any errors in the table. The repair type is the same as that specifiedwith the --recover or -r option.
myisamchk --force ...
--information
Print informational statistics about the table that is checked.
myisamchk --information ...
--medium-check
Do a check that is faster than an --extend-check operation. This finds only 99.99% of all errors, which should be good enough inmost cases.
myisamchk --medium-check ...
--read-only
Do not mark the table as checked. This is useful if you use myisamchk to check a table that is in use by some other applicationthat does not use locking, such as mysqld when run with external locking disabled.
myisamchk --read-only ...
--update-state
Store information in the .MYI file to indicate when the table was checked and whether the table crashed. This should be used toget full benefit of the --check-only-changed option, but you shouldn't use this option if the mysqld server is using the tableand you are running it with external locking disabled.MYISAMCHK REPAIR OPTIONSmyisamchk supports the following options for table repair operations (operations performed when an option such as --recover or
myisamchk --update-state ...
--backup
Make a backup of the .MYD file as file_name-time.BAK
myisamchk --backup ...
--character-sets-dir
The directory where character sets are installed. See Section 10.15, “Character Set Configuration”.
myisamchk --character-sets-dir ...
--correct-checksum
Correct the checksum information for the table.
myisamchk --correct-checksum ...
--data-file-length
The maximum length of the data file (when re-creating data file when it is “full”).
myisamchk --data-file-length ...
--keys-used
For myisamchk, the option value is a bit value that indicates which indexes to update. Each binary bit of the option valuecorresponds to a table index, where the first index is bit 0. An option value of 0 disables updates to all indexes, which can beused to get faster inserts. Deactivated indexes can be reactivated by using myisamchk -r.
myisamchk --keys-used ...
--no-symlinks
Do not follow symbolic links. Normally myisamchk repairs the table that a symlink points to. This option does not exist as ofMySQL 4.0 because versions from 4.0 on do not remove symlinks during repair operations.
myisamchk --no-symlinks ...
--max-record-length
Skip rows larger than the given length if myisamchk cannot allocate memory to hold them.
myisamchk --max-record-length ...
--parallel-recover
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!
myisamchk --parallel-recover ...
--quick
Achieve a faster repair by modifying only the index file, not the data file. You can specify this option twice to force myisamchkto modify the original data file in case of duplicate keys.
myisamchk --quick ...
--recover
Do a repair that can fix almost any problem except unique keys that are not unique (which is an extremely unlikely error withMyISAM tables). If you want to recover a table, this is the option to try first. You should try --safe-recover only if myisamchkreports that the table cannot be recovered using --recover. (In the unlikely case that --recover fails, the data file remainsintact.)If you have lots of memory, you should increase the value of myisam_sort_buffer_size.
myisamchk --recover ...
--safe-recover
Do a repair using an old recovery method that reads through all rows in order and updates all index trees based on the rowsfound. 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 thenwith --safe-recover only if --recover fails.If you have lots of memory, you should increase the value of key_buffer_size.
myisamchk --safe-recover ...
--set-collation
Specify the collation to use for sorting table indexes. The character set name is implied by the first part of the collationname.
myisamchk --set-collation ...
--sort-recover
Force myisamchk to use sorting to resolve the keys even if the temporary files would be very large.
myisamchk --sort-recover ...
--tmpdir
The path of the directory to be used for storing temporary files. If this is not set, myisamchk uses the value of the TMPDIRenvironment variable. --tmpdir can be set to a list of directory paths that are used successively in round-robin fashion forcreating temporary files. The separator character between directory names is the colon (:) on Unix and the semicolon (;) onWindows.
myisamchk --tmpdir ...
--unpack
Unpack a table that was packed with myisampack.OTHER MYISAMCHK OPTIONSmyisamchk supports the following options for actions other than table checks and repairs:
myisamchk --unpack ...
--analyze
Analyze the distribution of key values. This improves join performance by enabling the join optimizer to better choose the orderin which to join the tables and which indexes it should use. To obtain information about the key distribution, use a myisamchk
myisamchk --analyze ...
--description
--verbose tbl_name command or the SHOW INDEX FROM tbl_name statement.
myisamchk --description ...
--block-search
Find the record that a block at the given offset belongs to.
myisamchk --block-search ...
--set-auto-increment[
Force AUTO_INCREMENT numbering for new records to start at the given value (or higher, if there are existing records withAUTO_INCREMENT values this large). If value is not specified, AUTO_INCREMENT numbers for new records begin with the largest valuecurrently in the table, plus one.
myisamchk --set-auto-increment[ ...
--sort-index
Sort the index tree blocks in high-low order. This optimizes seeks and makes table scans that use indexes faster.
myisamchk --sort-index ...
--sort-records
Sort records according to a particular index. This makes your data much more localized and may speed up range-based SELECT andORDER BY operations that use this index. (The first time you use this option to sort a table, it may be very slow.) To determinea table's index numbers, use SHOW INDEX, which displays a table's indexes in the same order that myisamchk sees them. Indexes arenumbered beginning with 1.If keys are not packed (PACK_KEYS=0), they have the same length, so when myisamchk sorts and moves records, it just overwritesrecord offsets in the index. If keys are packed (PACK_KEYS=1), myisamchk must unpack key blocks first, then re-create indexes andpack the key blocks again. (In this case, re-creating indexes is faster than updating offsets for each index.)OBTAINING TABLE INFORMATION WITH MYISAMCHKTo obtain a description of a MyISAM table or statistics about it, use the commands shown here. The output from these commands isexplained later in this section.· myisamchk -d tbl_nameRuns myisamchk in “describe mode” to produce a description of your table. If you start the MySQL server with external lockingdisabled, myisamchk may report an error for a table that is updated while it runs. However, because myisamchk does not change thetable in describe mode, there is no risk of destroying data.· myisamchk -dv tbl_nameAdding -v runs myisamchk in verbose mode so that it produces more information about the table. Adding -v a second time produceseven more information.· myisamchk -eis tbl_nameShows only the most important information from a table. This operation is slow because it must read the entire table.· myisamchk -eiv tbl_nameThis is like -eis, but tells you what is being done.The tbl_name argument can be either the name of a MyISAM table or the name of its index file, as described in myisamchk(1). Multipletbl_name arguments can be given.Suppose that a table named person has the following structure. (The MAX_ROWS table option is included so that in the example outputfrom myisamchk shown later, some values are smaller and fit the output format more easily.)CREATE TABLE person(id INT NOT NULL AUTO_INCREMENT,last_name VARCHAR(20) NOT NULL,first_name VARCHAR(20) NOT NULL,birth DATE,death DATE,PRIMARY KEY (id),INDEX (last_name, first_name),INDEX (birth)) MAX_ROWS = 1000000 ENGINE=MYISAM;Suppose also that the table has these data and index file sizes:
myisamchk --sort-records ...
-rw-rw----
1 mysql mysql 9347072 Aug 19 11:47 person.MYD
myisamchk -rw-rw---- ...
-
block_size 1024:
myisamchk - ...
--write_buffer_size=64M
Using --myisam_sort_buffer_size=16M is probably enough for most cases.Be aware that myisamchk uses temporary files in TMPDIR. If TMPDIR points to a memory file system, out of memory errors can easilyoccur. If this happens, run myisamchk with the --tmpdir=dir_name option to specify a directory located on a file system that has morespace.When performing repair operations, myisamchk also needs a lot of disk space:· Twice the size of the data file (the original file and a copy). This space is not needed if you do a repair with --quick; in thiscase, only the index file is re-created. This space must be available on the same file system as the original data file, as thecopy is created in the same directory as the original.· Space for the new index file that replaces the old one. The old index file is truncated at the start of the repair operation, soyou usually ignore this space. This space must be available on the same file system as the original data file.· When using --recover or --sort-recover (but not when using --safe-recover), you need space on disk for sorting. This space isallocated in the temporary directory (specified by TMPDIR or --tmpdir=dir_name). The following formula yields the amount of spacerequired:(largest_key + row_pointer_length) * number_of_rows * 2You can check the length of the keys and the row_pointer_length with myisamchk -dv tbl_name (see the section called “OBTAININGTABLE INFORMATION WITH MYISAMCHK”). The row_pointer_length and number_of_rows values are the Datafile pointer and Data recordsvalues in the table description. To determine the largest_key value, check the Key lines in the table description. The Len columnindicates the number of bytes for each key part. For a multiple-column index, the key size is the sum of the Len values for allkey parts.If you have a problem with disk space during repair, you can try --safe-recover instead of --recover.COPYRIGHTCopyright © 1997, 2019, Oracle and/or its affiliates. All rights reserved.This documentation is free software; you can redistribute it and/or modify it only under the terms of the GNU General Public Licenseas published by the Free Software Foundation; version 2 of the License.This documentation is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.You should have received a copy of the GNU General Public License along with the program; if not, write to the Free SoftwareFoundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA or see http://www.gnu.org/licenses/.
myisamchk --write_buffer_size=64M ...