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\&.
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\&.
\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
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:
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
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\&.
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\&.
\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
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\&.
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
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\&.
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
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
SHOW INDEX, which displays a table\'s indexes in the same order that
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\&.)
The size of the data file pointer, in bytes\&. It is usually 2, 3, 4, or 5 bytes\&. Most tables manage with 2 bytes, but this cannot be controlled from MySQL yet\&. For fixed tables, this is a row address\&. For dynamic tables, this is a byte address\&.
.RE
.sp
.RS4
.ien\{\
\h'-04'\(bu\h'+03'\c
.\}
.el\{\
.sp-1
.IP\(bu2.3
.\}
Keyfile pointer
.sp
The size of the index file pointer, in bytes\&. It is usually 1, 2, or 3 bytes\&. Most tables manage with 2 bytes, but this is calculated automatically by MySQL\&. It is always a block address\&.
.RE
.sp
.RS4
.ien\{\
\h'-04'\(bu\h'+03'\c
.\}
.el\{\
.sp-1
.IP\(bu2.3
.\}
Max datafile length
.sp
How long the table data file can become, in bytes\&.
.RE
.sp
.RS4
.ien\{\
\h'-04'\(bu\h'+03'\c
.\}
.el\{\
.sp-1
.IP\(bu2.3
.\}
Max keyfile length
.sp
How long the table index file can become, in bytes\&.
.RE
.sp
.RS4
.ien\{\
\h'-04'\(bu\h'+03'\c
.\}
.el\{\
.sp-1
.IP\(bu2.3
.\}
Recordlength
.sp
How much space each row takes, in bytes\&.
.RE
.PP
The
table description
part of the output includes a list of all keys in the table\&. For each key,
\fBmyisamchk\fR
displays some low\-level information:
.sp
.RS4
.ien\{\
\h'-04'\(bu\h'+03'\c
.\}
.el\{\
.sp-1
.IP\(bu2.3
.\}
Key
.sp
This key\'s number\&. This value is shown only for the first column of the key\&. If this value is missing, the line corresponds to the second or later column of a multiple\-column key\&. For the table shown in the example, there are two
table description
lines for the second index\&. This indicates that it is a multiple\-part index with two parts\&.
.RE
.sp
.RS4
.ien\{\
\h'-04'\(bu\h'+03'\c
.\}
.el\{\
.sp-1
.IP\(bu2.3
.\}
Start
.sp
Where in the row this portion of the index starts\&.
.RE
.sp
.RS4
.ien\{\
\h'-04'\(bu\h'+03'\c
.\}
.el\{\
.sp-1
.IP\(bu2.3
.\}
Len
.sp
How long this portion of the index is\&. For packed numbers, this should always be the full length of the column\&. For strings, it may be shorter than the full length of the indexed column, because you can index a prefix of a string column\&. The total length of a multiple\-part key is the sum of the
Len
values for all key parts\&.
.RE
.sp
.RS4
.ien\{\
\h'-04'\(bu\h'+03'\c
.\}
.el\{\
.sp-1
.IP\(bu2.3
.\}
Index
.sp
Whether a key value can exist multiple times in the index\&. Possible values are
unique
or
multip\&.
(multiple)\&.
.RE
.sp
.RS4
.ien\{\
\h'-04'\(bu\h'+03'\c
.\}
.el\{\
.sp-1
.IP\(bu2.3
.\}
Type
.sp
What data type this portion of the index has\&. This is a
MyISAM
data type with the possible values
packed,
stripped, or
empty\&.
.RE
.sp
.RS4
.ien\{\
\h'-04'\(bu\h'+03'\c
.\}
.el\{\
.sp-1
.IP\(bu2.3
.\}
Root
.sp
Address of the root index block\&.
.RE
.sp
.RS4
.ien\{\
\h'-04'\(bu\h'+03'\c
.\}
.el\{\
.sp-1
.IP\(bu2.3
.\}
Blocksize
.sp
The size of each index block\&. By default this is 1024, but the value may be changed at compile time when MySQL is built from source\&.
.RE
.sp
.RS4
.ien\{\
\h'-04'\(bu\h'+03'\c
.\}
.el\{\
.sp-1
.IP\(bu2.3
.\}
Rec/key
.sp
This is a statistical value used by the optimizer\&. It tells how many rows there are per value for this index\&. A unique index always has a value of 1\&. This may be updated after a table is loaded (or greatly changed) with
\fBmyisamchk \-a\fR\&. If this is not updated at all, a default value of 30 is given\&.
.RE
.PP
The last part of the output provides information about each column:
.sp
.RS4
.ien\{\
\h'-04'\(bu\h'+03'\c
.\}
.el\{\
.sp-1
.IP\(bu2.3
.\}
Field
.sp
The column number\&.
.RE
.sp
.RS4
.ien\{\
\h'-04'\(bu\h'+03'\c
.\}
.el\{\
.sp-1
.IP\(bu2.3
.\}
Start
.sp
The byte position of the column within table rows\&.
.RE
.sp
.RS4
.ien\{\
\h'-04'\(bu\h'+03'\c
.\}
.el\{\
.sp-1
.IP\(bu2.3
.\}
Length
.sp
The length of the column in bytes\&.
.RE
.sp
.RS4
.ien\{\
\h'-04'\(bu\h'+03'\c
.\}
.el\{\
.sp-1
.IP\(bu2.3
.\}
Nullpos,
Nullbit
.sp
For columns that can be
NULL,
MyISAM
stores
NULL
values as a flag in a byte\&. Depending on how many nullable columns there are, there can be one or more bytes used for this purpose\&. The
Nullpos
and
Nullbit
values, if nonempty, indicate which byte and bit contains that flag indicating whether the column is
NULL\&.
.sp
The position and number of bytes used to store
NULL
flags is shown in the line for field 1\&. This is why there are six
Field
lines for the
person
table even though it has only five columns\&.
.RE
.sp
.RS4
.ien\{\
\h'-04'\(bu\h'+03'\c
.\}
.el\{\
.sp-1
.IP\(bu2.3
.\}
Type
.sp
The data type\&. The value may contain any of the following descriptors:
.sp
.RS4
.ien\{\
\h'-04'\(bu\h'+03'\c
.\}
.el\{\
.sp-1
.IP\(bu2.3
.\}
constant
.sp
All rows have the same value\&.
.RE
.sp
.RS4
.ien\{\
\h'-04'\(bu\h'+03'\c
.\}
.el\{\
.sp-1
.IP\(bu2.3
.\}
no endspace
.sp
Do not store endspace\&.
.RE
.sp
.RS4
.ien\{\
\h'-04'\(bu\h'+03'\c
.\}
.el\{\
.sp-1
.IP\(bu2.3
.\}
no endspace, not_always
.sp
Do not store endspace and do not do endspace compression for all values\&.
.RE
.sp
.RS4
.ien\{\
\h'-04'\(bu\h'+03'\c
.\}
.el\{\
.sp-1
.IP\(bu2.3
.\}
no endspace, no empty
.sp
Do not store endspace\&. Do not store empty values\&.
.RE
.sp
.RS4
.ien\{\
\h'-04'\(bu\h'+03'\c
.\}
.el\{\
.sp-1
.IP\(bu2.3
.\}
table\-lookup
.sp
The column was converted to an
ENUM\&.
.RE
.sp
.RS4
.ien\{\
\h'-04'\(bu\h'+03'\c
.\}
.el\{\
.sp-1
.IP\(bu2.3
.\}
zerofill(\fIN\fR)
.sp
The most significant
\fIN\fR
bytes in the value are always 0 and are not stored\&.
.RE
.sp
.RS4
.ien\{\
\h'-04'\(bu\h'+03'\c
.\}
.el\{\
.sp-1
.IP\(bu2.3
.\}
no zeros
.sp
Do not store zeros\&.
.RE
.sp
.RS4
.ien\{\
\h'-04'\(bu\h'+03'\c
.\}
.el\{\
.sp-1
.IP\(bu2.3
.\}
always zero
.sp
Zero values are stored using one bit\&.
.RE
.RE
.sp
.RS4
.ien\{\
\h'-04'\(bu\h'+03'\c
.\}
.el\{\
.sp-1
.IP\(bu2.3
.\}
Huff tree
.sp
The number of the Huffman tree associated with the column\&.
.RE
.sp
.RS4
.ien\{\
\h'-04'\(bu\h'+03'\c
.\}
.el\{\
.sp-1
.IP\(bu2.3
.\}
Bits
.sp
The number of bits used in the Huffman tree\&.
.RE
.PP
The
Huff tree
and
Bits
fields are displayed if the table has been compressed with
\fBmyisampack\fR\&. See
\fBmyisampack\fR(1), for an example of this information\&.
.PP
Example of
\fBmyisamchk \-eiv\fR
output:
.sp
.ifn\{\
.RS4
.\}
.nf
Checking MyISAM file: person
Data records: 306688 Deleted blocks: 0
\- check file\-size
\- check record delete\-chain
No recordlinks
\- check key delete\-chain
block_size 1024:
\- check index reference
\- check data record references index: 1
Key: 1: Keyblocks used: 98% Packed: 0% Max levels: 3
\- check data record references index: 2
Key: 2: Keyblocks used: 99% Packed: 97% Max levels: 3
\- check data record references index: 3
Key: 3: Keyblocks used: 98% Packed: \-14% Max levels: 3
What percentage of the keyblocks are used\&. When a table has just been reorganized with
\fBmyisamchk\fR, the values are very high (very near theoretical maximum)\&.
.RE
.sp
.RS4
.ien\{\
\h'-04'\(bu\h'+03'\c
.\}
.el\{\
.sp-1
.IP\(bu2.3
.\}
Packed
.sp
MySQL tries to pack key values that have a common suffix\&. This can only be used for indexes on
CHAR
and
VARCHAR
columns\&. For long indexed strings that have similar leftmost parts, this can significantly reduce the space used\&. In the preceding example, the second key is 40 bytes long and a 97% reduction in space is achieved\&.
.RE
.sp
.RS4
.ien\{\
\h'-04'\(bu\h'+03'\c
.\}
.el\{\
.sp-1
.IP\(bu2.3
.\}
Max levels
.sp
How deep the B\-tree for this key is\&. Large tables with long key values get high values\&.
.RE
.sp
.RS4
.ien\{\
\h'-04'\(bu\h'+03'\c
.\}
.el\{\
.sp-1
.IP\(bu2.3
.\}
Records
.sp
How many rows are in the table\&.
.RE
.sp
.RS4
.ien\{\
\h'-04'\(bu\h'+03'\c
.\}
.el\{\
.sp-1
.IP\(bu2.3
.\}
M\&.recordlength
.sp
The average row length\&. This is the exact row length for tables with fixed\-length rows, because all rows have the same length\&.
.RE
.sp
.RS4
.ien\{\
\h'-04'\(bu\h'+03'\c
.\}
.el\{\
.sp-1
.IP\(bu2.3
.\}
Packed
.sp
MySQL strips spaces from the end of strings\&. The
Packed
value indicates the percentage of savings achieved by doing this\&.
.RE
.sp
.RS4
.ien\{\
\h'-04'\(bu\h'+03'\c
.\}
.el\{\
.sp-1
.IP\(bu2.3
.\}
Recordspace used
.sp
What percentage of the data file is used\&.
.RE
.sp
.RS4
.ien\{\
\h'-04'\(bu\h'+03'\c
.\}
.el\{\
.sp-1
.IP\(bu2.3
.\}
Empty space
.sp
What percentage of the data file is unused\&.
.RE
.sp
.RS4
.ien\{\
\h'-04'\(bu\h'+03'\c
.\}
.el\{\
.sp-1
.IP\(bu2.3
.\}
Blocks/Record
.sp
Average number of blocks per row (that is, how many links a fragmented row is composed of)\&. This is always 1\&.0 for fixed\-format tables\&. This value should stay as close to 1\&.0 as possible\&. If it gets too large, you can reorganize the table\&. See
How many blocks (links) are used\&. For fixed\-format tables, this is the same as the number of rows\&.
.RE
.sp
.RS4
.ien\{\
\h'-04'\(bu\h'+03'\c
.\}
.el\{\
.sp-1
.IP\(bu2.3
.\}
Deleteblocks
.sp
How many blocks (links) are deleted\&.
.RE
.sp
.RS4
.ien\{\
\h'-04'\(bu\h'+03'\c
.\}
.el\{\
.sp-1
.IP\(bu2.3
.\}
Recorddata
.sp
How many bytes in the data file are used\&.
.RE
.sp
.RS4
.ien\{\
\h'-04'\(bu\h'+03'\c
.\}
.el\{\
.sp-1
.IP\(bu2.3
.\}
Deleted data
.sp
How many bytes in the data file are deleted (unused)\&.
.RE
.sp
.RS4
.ien\{\
\h'-04'\(bu\h'+03'\c
.\}
.el\{\
.sp-1
.IP\(bu2.3
.\}
Lost space
.sp
If a row is updated to a shorter length, some space is lost\&. This is the sum of all such losses, in bytes\&.
.RE
.sp
.RS4
.ien\{\
\h'-04'\(bu\h'+03'\c
.\}
.el\{\
.sp-1
.IP\(bu2.3
.\}
Linkdata
.sp
When the dynamic table format is used, row fragments are linked with pointers (4 to 7 bytes each)\&.
Linkdata
is the sum of the amount of storage used by all such pointers\&.
.RE
.SH"MYISAMCHK MEMORY USAGE"
.\" memory usage: myisamchk
.PP
Memory allocation is important when you run
\fBmyisamchk\fR\&.
\fBmyisamchk\fR
uses no more memory than its memory\-related variables are set to\&. If you are going to use
\fBmyisamchk\fR
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
\fBmyisamchk\fR
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):
points to a memory file system, out of memory errors can easily occur\&. If this happens, run
\fBmyisamchk\fR
with the
\fB\-\-tmpdir=\fR\fB\fIpath\fR\fR
option to specify a directory located on a file system that has more space\&.
.PP
When performing repair operations,
\fBmyisamchk\fR
also needs a lot of disk space:
.sp
.RS4
.ien\{\
\h'-04'\(bu\h'+03'\c
.\}
.el\{\
.sp-1
.IP\(bu2.3
.\}
Twice the size of the data file (the original file and a copy)\&. This space is not needed if you do a repair with
\fB\-\-quick\fR; in this case, only the index file is re\-created\&.
\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\&.
.RE
.sp
.RS4
.ien\{\
\h'-04'\(bu\h'+03'\c
.\}
.el\{\
.sp-1
.IP\(bu2.3
.\}
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\&.
.RE
.sp
.RS4
.ien\{\
\h'-04'\(bu\h'+03'\c
.\}
.el\{\
.sp-1
.IP\(bu2.3
.\}
When using
\fB\-\-recover\fR
or
\fB\-\-sort\-recover\fR
(but not when using
\fB\-\-safe\-recover\fR), you need space on disk for sorting\&. This space is allocated in the temporary directory (specified by
TMPDIR
or
\fB\-\-tmpdir=\fR\fB\fIpath\fR\fR)\&. The following formula yields the amount of space required:
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.
.PP
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.
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/.