Using
myisamchk
for Crash Recovery
634
you must make sure that the server does not use the tables at the same time so that there is no
unwanted interaction between
myisamchk
and the server.
7.6.1. Using
myisamchk
for Crash Recovery
This section describes how to check for and deal with data corruption in MySQL databases. If your
tables become corrupted frequently, you should try to find the reason why. See
Section C.5.4.2, “What
to Do If MySQL Keeps Crashing”
.
For an explanation of how
MyISAM
tables can become corrupted, see
Section 14.1.4, “
MyISAM
Table
Problems”
.
If you run
mysqld
with external locking disabled (which is the default), you cannot reliably use
myisamchk
to check a table when
mysqld
is using the same table. If you can be certain that no
one will access the tables through
mysqld
while you run
myisamchk
, you only have to execute
mysqladmin flush-tables
before you start checking the tables. If you cannot guarantee this, you
must stop
mysqld
while you check the tables. If you run
myisamchk
to check tables that
mysqld
is
updating at the same time, you may get a warning that a table is corrupt even when it is not.
If the server is run with external locking enabled, you can use
myisamchk
to check tables at any
time. In this case, if the server tries to update a table that
myisamchk
is using, the server will wait for
myisamchk
to finish before it continues.
If you use
myisamchk
to repair or optimize tables, you must always ensure that the
mysqld
server
is not using the table (this also applies if external locking is disabled). If you do not stop
mysqld
, you
should at least do a
mysqladmin flush-tables
before you run
myisamchk
. Your tables may
become corrupted if the server and
myisamchk
access the tables simultaneously.
When performing crash recovery, it is important to understand that each
MyISAM
table
tbl_name
in a
database corresponds to the three files in the database directory shown in the following table.
File
Purpose
tbl_name.frm
Definition (format) file
tbl_name.MYD
Data file
tbl_name.MYI
Index file
Each of these three file types is subject to corruption in various ways, but problems occur most often in
data files and index files.
myisamchk
works by creating a copy of the
.MYD
data file row by row. It ends the repair stage
by removing the old
.MYD
file and renaming the new file to the original file name. If you use
--
quick
[324]
,
myisamchk
does not create a temporary
.MYD
file, but instead assumes that the
.MYD
file is correct and generates only a new index file without touching the
.MYD
file. This is safe, because
myisamchk
automatically detects whether the
.MYD
file is corrupt and aborts the repair if it is. You can
also specify the
--quick
[324]
option twice to
myisamchk
. In this case,
myisamchk
does not abort
on some errors (such as duplicate-key errors) but instead tries to resolve them by modifying the
.MYD
file. Normally the use of two
--quick
[324]
options is useful only if you have too little free disk space
to perform a normal repair. In this case, you should at least make a backup of the table before running
myisamchk
.
7.6.2. How to Check
MyISAM
Tables for Errors
To check a
MyISAM
table, use the following commands:
•
myisamchk tbl_name
This finds 99.99% of all errors. What it cannot find is corruption that involves only the data file (which
is very unusual). If you want to check a table, you should normally run
myisamchk
without options or
with the
-s
(silent) option.
Summary of Contents for 5.0
Page 1: ...MySQL 5 0 Reference Manual ...
Page 18: ...xviii ...
Page 60: ...40 ...
Page 396: ...376 ...
Page 578: ...558 ...
Page 636: ...616 ...
Page 844: ...824 ...
Page 1234: ...1214 ...
Page 1427: ...MySQL Proxy Scripting 1407 ...
Page 1734: ...1714 ...
Page 1752: ...1732 ...
Page 1783: ...Configuring Connector ODBC 1763 ...
Page 1793: ...Connector ODBC Examples 1773 ...
Page 1839: ...Connector Net Installation 1819 2 You must choose the type of installation to perform ...
Page 2850: ...2830 ...
Page 2854: ...2834 ...
Page 2928: ...2908 ...
Page 3000: ...2980 ...
Page 3122: ...3102 ...
Page 3126: ...3106 ...
Page 3174: ...3154 ...
Page 3232: ...3212 ...