Check and repair MySQL datasheet

Source: Internet
Author: User
Tags extend mysql delete

The first is the fastest, to fix the most common problems, and the last one is the slowest to fix problems that some other methods cannot fix.

Review and repair MySQL data files
If the above method cannot fix a damaged table, you can try these two techniques before you give up:

If you suspect that the index file of the table (*. Myi An unrecoverable error occurred, or even lost the file, you can use the data file (*. MYD) and the data format file (*.FRM) to regenerate it. First, make a copy of the data file (TBLNAME.MYD). To restart your MySQL service and connect to this service, delete the contents of the table using the following command:

MySQL DELETE from Tblname;

When you delete the contents of a table, a new index file is created. Quit logging on and shut down the service and overwrite the new (empty) data file with the data file (tblname.myd) you just saved. Finally, use MYISAMCHK to perform a standard fix (the second method above) to regenerate index data based on the contents of the table's data and the table's format file.

If your table's format file (TBLNAME.FRM) is missing or an unrecoverable error occurs, but you know how to regenerate the table using the corresponding CREATE TABLE statement, you can regenerate a new. frm file and and your data files and index files ( If there is a problem with the index file, use the method above to reconstruct a new one. First make a copy of the data and index file, and then delete the original file (delete all the records in the data directory about the table).

Start the MySQL service and create a new table using the original CREATE table file. The new. frm file should work, but the best thing to do is to perform the standard fix (the second method above).

You can use the MySQL statement to $table with the CHECK TABLE; Where $table represents the name of the datasheet, the detection table is damaged, if the damage can be repair table $table to repair, if not, you can repair more than a few times!

If you use Win server, you can log into the DB server, enter this path, do not go into MySQL

D:CD MYSQL

D:MYSQL>CD BIN

D:mysqlbin>myisamchk-r d:mysqldataguildmsg_table.myi (msg_table)
-Check Key Delete-chain
-Check record Delete-chain
-Recovering (with sort) myisam-table ' d:mysqldataguildmsg_table.myi '
Data records:23
-Fixing Index 1

D:mysqlbin>myisamchk--safe-recover D:mysqldataguildmsg_table.myi
-Recovering (with Keycache) myisam-table ' d:mysqldataguildmsg_table.myi '
Data records:89

D:mysqlbin>

When you don't know which table is broken, you can go to the MySQL database:
Use Guild;
Desc msg_table; See if Msg_table is bad.

Fixed the access to the MySQL database in the command check: Show table;

To check for errors in a table, you only need to run Myisamchk (in the MySQL bin directory) and provide the location and table name of the file, or the index file name of the table:

Myisamchk/usr/local/mysql/var/dbname/tblname
Myisamchk/usr/local/mysql/var/dbname/tblname.myi

All two of the above commands can perform a check on the specified table. To check all tables in the database, you can use wildcard characters:

myisamchk/usr/local/mysql/var/dbname/*. Myi

To check all tables in all databases, you can use two wildcard characters: myisamchk/usr/local/mysql/var/*/*. Myi

If you do not have any options, MYISAMCHK will perform a normal check on the table file. If you have doubts about a table, but the normal check does not detect any errors, you can perform a more thorough check (but also slower!). ), which requires the use of the--extend-check option:

Myisamchk--extend-check/path/to/tblname

Checking for errors is not destructive, which means you don't have to worry that performing a check on your data files will make the existing problems worse. On the other hand, the fix option, while usually safe, does not undo changes to your data file. For this reason, we strongly recommend that you try to repair a corrupted table file first by making a backup and make sure that your MySQL service is off before making this backup.

When you try to fix a problem with a damaged table, there are three types of fixes. If you get an error message stating that a temporary file cannot be created, delete the file indicated by the information and try again-this is usually the legacy of the last repair operation.
The three repair methods are as follows:

Myisamchk--recover--quick/path/to/tblname
Myisamchk--recover/path/to/tblname
    myisamchk--safe-recover/path/to/tblname    

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.