1
.\" Title: \fBmyisamchk\fR
3
.\" Generator: DocBook XSL Stylesheets v1.70.1 <http://docbook.sf.net/>
5
.\" Manual: MySQL Database System
8
.TH "\fBMYISAMCHK\fR" "1" "05/23/2009" "MySQL 6.0" "MySQL Database System"
9
.\" disable hyphenation
11
.\" disable justification (adjust text to left margin only)
14
myisamchk \- MyISAM table\-maintenance utility
17
\fBmyisamchk [\fR\fB\fIoptions\fR\fR\fB] \fR\fB\fItbl_name\fR\fR\fB ...\fR
22
utility gets information about your database tables or checks, repairs, or optimizes them.
26
tables (tables that have
30
files for storing data and indexes).
34
with partitioned tables is not supported.
37
.nr an-no-space-flag 1
42
It is best to make a backup of a table before performing a table repair operation; under some circumstances the operation might cause data loss. Possible causes include but are not limited to file system errors.
50
shell> \fBmyisamchk [\fR\fB\fIoptions\fR\fR\fB] \fR\fB\fItbl_name\fR\fR\fB ...\fR
58
to do. They are described in the following sections. You can also get a list of options by invoking
59
\fBmyisamchk \-\-help\fR.
63
simply checks your table as the default operation. To get more information or to tell
65
to take corrective action, specify options as described in the following discussion.
68
is the database table you want to check or repair. If you run
70
somewhere other than in the database directory, you must specify the path to the database directory, because
72
has no idea where the database is located. In fact,
74
does not actually care whether the files you are working on are located in a database directory. You can copy the files that correspond to a database table into some other location and perform recovery operations on them there.
76
You can name several tables on the
78
command line if you wish. You can also specify a table by naming its index file (the file with the
80
suffix). This allows you to specify all tables in a directory by using the pattern
81
\fI*.MYI\fR. For example, if you are in a database directory, you can check all the
83
tables in that directory like this:
87
shell> \fBmyisamchk *.MYI\fR
91
If you are not in the database directory, you can check all the tables there by specifying the path to the directory:
95
shell> \fBmyisamchk \fR\fB\fI/path/to/database_dir/\fR\fR\fB*.MYI\fR
99
You can even check all tables in all databases by specifying a wildcard with the path to the MySQL data directory:
103
shell> \fBmyisamchk \fR\fB\fI/path/to/datadir/*/*\fR\fR\fB.MYI\fR
107
The recommended way to quickly check all
113
shell> \fBmyisamchk \-\-silent \-\-fast \fR\fB\fI/path/to/datadir/*/*\fR\fR\fB.MYI\fR
117
If you want to check all
119
tables and repair any that are corrupted, you can use the following command:
123
shell> \fBmyisamchk \-\-silent \-\-force \-\-fast \-\-update\-state \\\fR
124
\fB\-\-key_buffer_size=64M \-\-sort_buffer_size=64M \\\fR
125
\fB\-\-read_buffer_size=1M \-\-write_buffer_size=1M \\\fR
126
\fB\fI/path/to/datadir/*/*\fR\fR\fB.MYI\fR
130
This command assumes that you have more than 64MB free. For more information about memory allocation with
132
the section called \(lq\fBMYISAMCHK\fR MEMORY USAGE\(rq.
135
.nr an-no-space-flag 1
140
\fIYou must ensure that no other program is using the tables while you are running \fR\fI\fBmyisamchk\fR\fR. The most effective means of doing so is to shut down the MySQL server while running
141
\fBmyisamchk\fR, or to lock all tables that
145
Otherwise, when you run
146
\fBmyisamchk\fR, it may display the following error message:
150
warning: clients are using or haven't closed the table properly
154
This means that you are trying to check a table that has been updated by another program (such as the
156
server) that hasn't yet closed the file or that has died without closing the file properly, which can sometimes lead to the corruption of one or more
162
is running, you must force it to flush any table modifications that are still buffered in memory by using
163
FLUSH TABLES. You should then ensure that no one is using the tables while you are running
166
However, the easiest way to avoid this problem is to use
171
Section\ 12.5.2.2, \(lqCHECK TABLE Syntax\(rq.
174
supports the options in the following table. It also reads option files and supports the options for processing them described at
175
Section\ 4.2.3.2.1, \(lqCommand\-Line Options that Affect Option\-File Handling\(rq.
176
.SH "\fBMYISAMCHK\fR GENERAL OPTIONS"
178
The options described in this section can be used for any type of table maintenance operation performed by
179
\fBmyisamchk\fR. The sections following this one describe options that pertain only to specific operations, such as table checking or repairing.
185
Display a help message and exit. Options are grouped by type of operation.
191
Display a help message and exit. Options are presented in a single list.
194
\fB\-\-debug=\fR\fB\fIdebug_options\fR\fR\fB, \-# \fR\fB\fIdebug_options\fR\fR
196
Write a debugging log. A typical
199
\'d:t:o,\fIfile_name\fR'. The default is
200
\'d:t:o,/tmp/myisamchk.trace'.
206
Silent mode. Write output only when errors occur. You can use
208
twice (\fB\-ss\fR) to make
216
Verbose mode. Print more information about what the program does. This can be used with
221
multiple times (\fB\-vv\fR,
222
\fB\-vvv\fR) for even more output.
228
Display version information and exit.
234
Instead of terminating with an error if the table is locked, wait until the table is unlocked before continuing. If you are running
236
with external locking disabled, the table can be locked only by another
242
You can also set the following variables by using
243
\fB\-\-\fR\fB\fIvar_name\fR\fR\fB=\fR\fB\fIvalue\fR\fR
324
variables and their default values can be examined with
325
\fBmyisamchk \-\-help\fR:
328
is used when the keys are repaired by sorting keys, which is the normal case when you use
332
is used when you are checking the table with
333
\fB\-\-extend\-check\fR
334
or when the keys are repaired by inserting keys row by row into the table (like when doing normal inserts). Repairing through the key buffer is used in the following cases:
338
\fB\-\-safe\-recover\fR.
341
The temporary files needed to sort the keys would be more than twice as big as when creating the key file directly. This is often the case when you have large key values for
345
columns, because the sort operation needs to store the complete key values as it proceeds. If you have lots of temporary space and you can force
347
to repair by sorting, you can use the
348
\fB\-\-sort\-recover\fR
353
Repairing through the key buffer takes much less disk space than using sorting, but is also much slower.
355
If you want a faster repair, set the
359
variables to about 25% of your available memory. You can set both variables to large values, because only one of them is used at a time.
362
is the size used for index blocks.
367
values are treated for index statistics collection when the
369
option is given. It acts like the
371
system variable. For more information, see the description of
374
Section\ 5.1.3, \(lqServer System Variables\(rq, and
375
Section\ 7.4.6, \(lqMyISAM Index Statistics Collection\(rq. For MySQL 6.0,
377
was added in MySQL 5.0.14. For older versions, the statistics collection method is equivalent to
384
variables are available as of MySQL 4.0.0.
386
is available as of MySQL 4.0.19.
391
indicate the minimum and maximum word length for
395
names the stopword file. These need to be set under the following circumstances.
399
to perform an operation that modifies table indexes (such as repair or analyze), the
401
indexes are rebuilt using the default full\-text parameter values for minimum and maximum word length and the stopword file unless you specify otherwise. This can result in queries failing.
403
The problem occurs because these parameters are known only by the server. They are not stored in
405
index files. To avoid the problem if you have modified the minimum or maximum word length or the stopword file in the server, specify the same
412
\fBmysqld\fR. For example, if you have set the minimum word length to 3, you can repair a table with
418
shell> \fBmyisamchk \-\-recover \-\-ft_min_word_len=3 \fR\fB\fItbl_name\fR\fR\fB.MYI\fR
424
and the server use the same values for full\-text parameters, you can place each one in both the
428
sections of an option file:
439
An alternative to using
445
ALTER TABLE. These statements are performed by the server, which knows the proper full\-text parameter values to use.
446
.SH "\fBMYISAMCHK\fR CHECK OPTIONS"
449
supports the following options for table checking operations:
455
Check the table for errors. This is the default operation if you specify no option that selects an operation type explicitly.
458
\fB\-\-check\-only\-changed\fR,
461
Check only tables that have changed since the last check.
464
\fB\-\-extend\-check\fR,
467
Check the table very thoroughly. This is quite slow if the table has many indexes. This option should only be used in extreme cases. Normally,
470
\fBmyisamchk \-\-medium\-check\fR
471
should be able to determine whether there are any errors in the table.
474
\fB\-\-extend\-check\fR
475
and have plenty of memory, setting the
477
variable to a large value helps the repair operation run faster.
483
Check only tables that haven't been closed properly.
489
Do a repair operation automatically if
491
finds any errors in the table. The repair type is the same as that specified with the
498
\fB\-\-information\fR,
501
Print informational statistics about the table that is checked.
504
\fB\-\-medium\-check\fR,
507
Do a check that is faster than an
508
\fB\-\-extend\-check\fR
509
operation. This finds only 99.99% of all errors, which should be good enough in most cases.
512
\fB\-\-read\-only\fR,
515
Do not mark the table as checked. This is useful if you use
517
to check a table that is in use by some other application that does not use locking, such as
519
when run with external locking disabled.
522
\fB\-\-update\-state\fR,
525
Store information in the
527
file to indicate when the table was checked and whether the table crashed. This should be used to get full benefit of the
528
\fB\-\-check\-only\-changed\fR
529
option, but you shouldn't use this option if the
531
server is using the table and you are running it with external locking disabled.
532
.SH "\fBMYISAMCHK\fR REPAIR OPTIONS"
535
supports the following options for table repair operations:
544
\fI\fIfile_name\fR\fR\fI\-\fR\fI\fItime\fR\fR\fI.BAK\fR
547
\fB\-\-character\-sets\-dir=\fR\fB\fIpath\fR\fR
549
The directory where character sets are installed. See
550
Section\ 9.2, \(lqThe Character Set Used for Data and Sorting\(rq.
553
\fB\-\-correct\-checksum\fR
555
Correct the checksum information for the table.
558
\fB\-\-data\-file\-length=\fR\fB\fIlen\fR\fR\fB, \-D \fR\fB\fIlen\fR\fR
560
Maximum length of the data file (when re\-creating data file when it is
564
\fB\-\-extend\-check\fR,
567
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.
573
Overwrite old intermediate files (files with names like
574
\fI\fItbl_name\fR\fR\fI.TMD\fR) instead of aborting.
577
\fB\-\-keys\-used=\fR\fB\fIval\fR\fR,
578
\fB\-k \fR\fB\fIval\fR\fR
581
\fBmyisamchk\fR, 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
585
\fB\-\-no\-symlinks\fR,
588
Do not follow symbolic links. Normally
590
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.
593
\fB\-\-max\-record\-length=\fR\fB\fIlen\fR\fR
595
Skip rows larger than the given length if
597
cannot allocate memory to hold them.
600
\fB\-\-parallel\-recover\fR,
603
Uses the same technique as
606
\fB\-n\fR, but creates all the keys in parallel, using different threads.
607
\fIThis is beta\-quality code. Use at your own risk!\fR
613
Achieve a faster repair by not modifying the data file. You can specify this option twice to force
615
to modify the original data file in case of duplicate keys.
621
Do a repair that can fix almost any problem except unique keys that are not unique (which is an extremely unlikely error with
623
tables). If you want to recover a table, this is the option to try first. You should try
624
\fB\-\-safe\-recover\fR
627
reports that the table cannot be recovered using
628
\fB\-\-recover\fR. (In the unlikely case that
630
fails, the data file remains intact.)
632
If you have lots of memory, you should increase the value of
636
\fB\-\-safe\-recover\fR,
639
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
640
\fB\-\-recover\fR, but can handle a couple of very unlikely cases that
642
cannot. This recovery method also uses much less disk space than
643
\fB\-\-recover\fR. Normally, you should repair first using
644
\fB\-\-recover\fR, and then with
645
\fB\-\-safe\-recover\fR
650
If you have lots of memory, you should increase the value of
654
\fB\-\-set\-character\-set=\fR\fB\fIname\fR\fR
656
Change the character set used by the table indexes. This option was replaced by
657
\fB\-\-set\-collation\fR
661
\fB\-\-set\-collation=\fR\fB\fIname\fR\fR
663
Specify the collation to use for sorting table indexes. The character set name is implied by the first part of the collation name.
666
\fB\-\-sort\-recover\fR,
671
to use sorting to resolve the keys even if the temporary files would be very large.
674
\fB\-\-tmpdir=\fR\fB\fIpath\fR\fR,
675
\fB\-t \fR\fB\fIpath\fR\fR
677
Path of the directory to be used for storing temporary files. If this is not set,
679
uses the value of the
681
environment variable.
683
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 (\(lq:\(rq) on Unix and the semicolon (\(lq;\(rq) on Windows, NetWare, and OS/2.
689
Unpack a table that was packed with
691
.SH "OTHER MYISAMCHK OPTIONS"
694
supports the following options for actions other than table checks and repairs:
700
Analyze the distribution of key values. This improves join performance by enabling the join optimizer to better choose the order in which to join the tables and which indexes it should use. To obtain information about the key distribution, use a
701
\fBmyisamchk \-\-description \-\-verbose \fR\fB\fItbl_name\fR\fR
703
SHOW INDEX FROM \fItbl_name\fR
707
\fB\-\-block\-search=\fR\fB\fIoffset\fR\fR,
708
\fB\-b \fR\fB\fIoffset\fR\fR
710
Find the record that a block at the given offset belongs to.
713
\fB\-\-description\fR,
716
Print some descriptive information about the table.
719
\fB\-\-set\-auto\-increment[=\fR\fB\fIvalue\fR\fR\fB]\fR,
720
\fB\-A[\fR\fB\fIvalue\fR\fR\fB]\fR
724
numbering for new records to start at the given value (or higher, if there are existing records with
726
values this large). If
730
numbers for new records begin with the largest value currently in the table, plus one.
733
\fB\-\-sort\-index\fR,
736
Sort the index tree blocks in high\-low order. This optimizes seeks and makes table scans that use indexes faster.
739
\fB\-\-sort\-records=\fR\fB\fIN\fR\fR,
740
\fB\-R \fR\fB\fIN\fR\fR
742
Sort records according to a particular index. This makes your data much more localized and may speed up range\-based
746
operations that use this index. (The first time you use this option to sort a table, it may be very slow.) To determine a table's index numbers, use
747
SHOW INDEX, which displays a table's indexes in the same order that
749
sees them. Indexes are numbered beginning with 1.
751
If keys are not packed (PACK_KEYS=0), they have the same length, so when
753
sorts and moves records, it just overwrites record offsets in the index. If keys are packed (PACK_KEYS=1),
755
must unpack key blocks first, then re\-create indexes and pack the key blocks again. (In this case, re\-creating indexes is faster than updating offsets for each index.)
756
.SH "\fBMYISAMCHK\fR MEMORY USAGE"
758
Memory allocation is important when you run
761
uses no more memory than its memory\-related variables are set to. If you are going to use
763
on very large tables, you should first decide how much memory you want it to use. The default is to use only about 3MB to perform repairs. By using larger values, you can get
765
to operate faster. For example, if you have more than 32MB RAM, you could use options such as these (in addition to any other options you might specify):
769
shell> \fBmyisamchk \-\-sort_buffer_size=16M \-\-key_buffer_size=16M \\\fR
770
\fB\-\-read_buffer_size=1M \-\-write_buffer_size=1M ...\fR
775
\fB\-\-sort_buffer_size=16M\fR
776
should probably be enough for most cases.
780
uses temporary files in
783
points to a memory file system, you may easily get out of memory errors. If this happens, run
786
\fB\-\-tmpdir=\fR\fB\fIpath\fR\fR
787
option to specify some directory located on a file system that has more space.
791
also needs a lot of disk space:
794
Double the size of the data file (the original file and a copy). This space is not needed if you do a repair with
795
\fB\-\-quick\fR; in this case, only the index file is re\-created.
796
\fIThis space must be available on the same file system as the original data file\fR, as the copy is created in the same directory as the original.
799
Space for the new index file that replaces the old one. The old index file is truncated at the start of the repair operation, so you usually ignore this space. This space must be available on the same file system as the original data file.
805
\fB\-\-sort\-recover\fR
807
\fB\-\-safe\-recover\fR), you need space for a sort buffer. The following formula yields the amount of space required:
811
(\fIlargest_key\fR + \fIrow_pointer_length\fR) \(mu \fInumber_of_rows\fR \(mu 2
814
You can check the length of the keys and the
817
\fBmyisamchk \-dv \fR\fB\fItbl_name\fR\fR. This space is allocated in the temporary directory (specified by
820
\fB\-\-tmpdir=\fR\fB\fIpath\fR\fR).
824
If you have a problem with disk space during repair, you can try
825
\fB\-\-safe\-recover\fR
830
Copyright 2007\-2008 MySQL AB, 2009 Sun Microsystems, Inc.
832
This documentation is free software; you can redistribute it and/or modify it only under the terms of the GNU General Public License as published by the Free Software Foundation; version 2 of the License.
834
This documentation is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
836
You should have received a copy of the GNU General Public License along with the program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110\-1301 USA or see http://www.gnu.org/licenses/.
838
For more information, please refer to the MySQL Reference Manual,
839
which may already be installed locally and which is also available
840
online at http://dev.mysql.com/doc/.
842
Sun Microsystems, Inc. (http://www.mysql.com/).