Three ways for MySQL to repair tables

Source: Internet
Author: User
Maybe many people have encountered the class Can 'topenfile: '[Table] mytable. the myi' error message does not know how to solve it. Next we will introduce that, in most cases, database corruption only means that the index file is damaged, the real data is damaged in rare cases. Most forms of database corruption can be easily repaired. And the previous school

Maybe many people have encountered the class Can 'topenfile: '[Table] mytable. the myi' error message does not know how to solve it. Next we will introduce that, in most cases, database corruption only means that the index file is damaged, the real data is damaged in rare cases. Most forms of database corruption can be easily repaired. And the previous school

Many people may have encountered an error message like Can't open file: '[Table] mytable. myi', but do not know how to solve it. Let's introduce it as follows,

In most cases, the database is damaged only when the index file is damaged, and the real data is damaged rarely. Most forms of database corruption can be easily repaired.

As with the previous verification, there are three methods to fix the vulnerability.

The method described below is only valid for tables in MyISAM format. Other types of damages must be recovered from the backup.

1. repair table SQL statement (mysql service must be running ).

2. Command mysqlcheck (mysql service can be running ).

3. Command myisamchk (mysql service must be stopped or the operated table is inactive ).

When repairing a table, you 'd better back up the table first. So you need two times the hard disk space of the original table. Make sure that your disk space is not used up before the restoration.

1. Use the "repair table" method to fix

Syntax: repair table name [Option]

The options are as follows:

QUICK is the fastest speed when the data table has not been modified

EXTENDED attempts to restore each data row will produce some junk data rows.

USE_FRM is used when the. MYI file is lost or the header is damaged. Re-indexing using the definition of. frm

In most cases, you can simply use "repair table tablename" without the option. However, this method does not work when the. MYI file is lost or the header is damaged,

For example:

Mysql> repair table mytable;

When the repair fails, the index file is lost or its header is damaged. To use the relevant definition file for repair, you need to use the USE_FRM option. For example:

Mysql> repair table mytable USE_FRM;

We can see that the output information of the Msg_test table item is "OK", and the table name has successfully repaired the damaged table.

Http://bbs.landingbj.com/t-0-250391-1.html

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.