MyISAM
Table Optimization
637
Stage 3: Difficult repair
You should reach this stage only if the first 16KB block in the index file is destroyed or contains
incorrect information, or if the index file is missing. In this case, it is necessary to create a new index
file. Do so as follows:
1. Move the data file to a safe place.
2. Use the table description file to create new (empty) data and index files:
shell>
mysql db_name
mysql>
SET autocommit=1;
mysql>
TRUNCATE TABLE tbl_name;
mysql>
quit
3. Copy the old data file back onto the newly created data file. (Do not just move the old file back onto
the new file. You want to retain a copy in case something goes wrong.)
Important
If you are using replication, you should stop it prior to performing the above
procedure, since it involves file system operations, and these are not logged by
MySQL.
Go back to Stage 2.
myisamchk -r -q
should work. (This should not be an endless loop.)
You can also use the
REPAIR TABLE tbl_name USE_FRM
SQL statement, which performs
the whole procedure automatically. There is also no possibility of unwanted interaction between
a utility and the server, because the server does all the work when you use
REPAIR TABLE
. See
Section 13.7.2.6, “
REPAIR TABLE
Syntax”
.
Stage 4: Very difficult repair
You should reach this stage only if the
.frm
description file has also crashed. That should never
happen, because the description file is not changed after the table is created:
1. Restore the description file from a backup and go back to Stage 3. You can also restore the index
file and go back to Stage 2. In the latter case, you should start with
myisamchk -r
.
2. If you do not have a backup but know exactly how the table was created, create a copy of the table
in another database. Remove the new data file, and then move the
.frm
description and
.MYI
index files from the other database to your crashed database. This gives you new description and
index files, but leaves the
.MYD
data file alone. Go back to Stage 2 and attempt to reconstruct the
index file.
7.6.4.
MyISAM
Table Optimization
To coalesce fragmented rows and eliminate wasted space that results from deleting or updating rows,
run
myisamchk
in recovery mode:
shell>
myisamchk -r tbl_name
You can optimize a table in the same way by using the
OPTIMIZE TABLE
SQL statement.
OPTIMIZE
TABLE
does a table repair and a key analysis, and also sorts the index tree so that key lookups are
faster. There is also no possibility of unwanted interaction between a utility and the server, because the
server does all the work when you use
OPTIMIZE TABLE
. See
Section 13.7.2.5, “
OPTIMIZE TABLE
Syntax”
.
myisamchk
has a number of other options that you can use to improve the performance of a table:
•
--analyze
[325]
or
-a
: Perform key distribution analysis. 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.
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 ...