MySQL's Myisamchk

Source: Internet
Author: User
Tags file copy index sort unpack

Description, check and repair of MyISAM tables.
Used without options all tables on the command would be a checked for errors
Usage:myisamchk [OPTIONS] tables[. MYI]

Global Options:
-H,--help display this Help and exit.
-?,--help display this help and exit.
-O,--set-var Iable var=option.
Change the value of a variable. Please note the
this option was deprecated; You can set variables
directly with '--variable-name=value '.
-T,- -tmpdir=path path for temporary files. Multiple paths can is
specified, separated by colon (:), they'll be used
in a round-robin fashion.
-S,--sil ENT only print errors. One can use Two-s to make
Myisamchk very silent.
-V,--verbose Print more information. This can is used with
--description and--check. Use the many-v for more verbosity.
-V,--version Print version and exit.
-W,--wait wait if table is locked.

Check options (check is the default action for Myisamchk):
-C,--check check table for errors.
-E,--extend-check Check the table VERY throughly. Only with this in
Extreme cases as myisamchk should normally be able to
Find out if the table was OK even without this switch.
-F,--fast Check only tables that haven ' t been closed properly.
-C,--check-only-changed
Check only tables this has changed since last check.
-F,--force Restart with '-R ' if there is any errors in the table.
States is updated as with '--update-state '.
-I,--information Print statistics information about table-is checked.
-M,--medium-check Faster than Extend-check, but only finds 99.99% of
All errors. Should is good enough for most cases.
-U--update-state Mark tables as crashed if you find any errors.
-T,--read-only Don ' T Mark table as checked.

Repair options (when using '-R ' or '-o '):
-B,--backup make a backup of the. MYD file as ' Filename-time. BAK '.
--correct-checksum correct checksum information for table.
-D,--data-file-length=# Max length of data file (when recreating data
File when it's full).
-E,--extend-check Try to recover every possible row from the data file
Normally this would also find a lot of garbage rows;
Don ' t use this option if you're not totally desperate.
-F,--force Overwrite old temporary files.
-K,--keys-used=# tell MyISAM to update only some specific keys. # is a
Bit mask of which keys to use. This can is used to
Get faster inserts.
--max-record-length=#
Skip rows bigger than this if Myisamchk can ' t allocate
Memory to hold it.
-R,--recover Can fix almost anything except unique keys that aren ' t
Unique.
-N,--sort-recover forces recovering with sorting even if the temporary
File would be very big.
-P,--parallel-recover
Uses the same technique as '-R ' and '-n ', but creates
All the keys in parallel, in different threads.
-O,--safe-recover Uses old recovery method; Slower than '-R ' but can
Handle a couple of cases where '-R ' reports that it
Can ' t fix the data file.
--character-sets-dir= ...
Directory where character sets is.
--set-collation=name
The collation used by the index.
-Q,--quick Faster repair by not modifying the data file.
One can give a second '-Q ' to force Myisamchk to
Modify the original datafile in case of duplicate keys.
Note:tables where the data file is currupted can ' t be
Fixed with this option.
-U,--unpack unpack file packed with Myisampack.

Other actions:
-A,--analyze analyze distribution of keys. Would make some joins in
MySQL faster. You can check the calculated distribution
By using '--description--verbose table_name '.
--STATS_METHOD=NAME specifies how index statistics collection code should
Treat NULLs. Possible values of name are "Nulls_unequal"
(Default for 4.1/5.0), "Nulls_equal" (Emulate 4.0), and
"Nulls_ignored".
-D,--description Prints some information about table.
-A,--set-auto-increment[=value]
Force Auto_increment to start on this or higher value
If no value is given and then sets the next auto_increment
Value to the highest used value for the auto key + 1.
-S,--sort-index sort index blocks. This speeds up ' read-next ' in
Applications.
-R,--sort-records=#
Sort records according to an index. This makes your
Data much more localized and could speed up things
(It May is VERY slow to do a sort the first time!).
-B,--block-search=#
Find a record, a block at given offset belongs to.

Because of a temporary power outage, using kill-9 to abort the MySQL service process, all of which can destroy MySQL data files. If the service is changing the file while it is being disturbed, the file may leave an incorrect or inconsistent state. Because such destruction is sometimes not easy to find, it can be a long time since you found this error.  So, when you find this problem, maybe all the backups have the same error. Myisamchk creates one line by row. MYD "(data) file copy works, it is deleted by the old". MYD file and rename the new file to the original filename end of the repair phase. If you use--quick,myisamchk do not create a temporary ". MYD "file, just assume". MYD "file is correct and only creates a new index file, do not touch". MYD "file, which is safe because MYISAMCHK is automatically detected." MYD "file is corrupted and in this case, discard the fix. You can also give Myisamchk the option of two--quick. In this case, MYISAMCHK will not give up on some errors (like duplicate keys), instead trying to modify ". MYD "file to resolve them. Typically, using the two--quick option is only useful if you implement a normal fix on too little free disk space. In this case, you should make at least one backup before running Myisamchk.

1, Myisamchk
The MySQL server must be temporarily stopped using MYISAMCHK. For example, we want to overhaul the test database. Perform the following actions:

# service mysqld stop; # myisamchk-r/var/lib/mysql/test/*myi# service mysqld start;

Myisamchk automatically checks and repairs index errors in the data table.

2, Mysqlcheck
With Mysqlcheck, you can perform a hot fix without stopping MySQL.

#mysqlcheck –r DBname Tablename–uuser–ppassword

Note that, in general, do not use the-F force fix, either Myisamchk or Mysqlcheck, and the-f parameter will be removed when a generic fix is unsuccessful

MySQL's Myisamchk

Related Keywords:
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.