Three methods for restoring MySQL Data Files

Source: Internet
Author: User
Tags mysql delete

MySQL data files may be damaged due to some reasons. Therefore, how to fix MySQL data files becomes a problem we need to know. Here are three methods to fix MySQL data files.

There are three repair types when you try to fix a broken table. If you get an error message indicating that a temporary file cannot be created, delete the file indicated by the Information and try again-this is typically left behind by the last repair operation.

The three methods for restoring MySQL Data Files are as follows:

Myisamchk -- recover -- quick/path/to/tblName

Myisamchk -- recover/path/to/tblName

Myisamchk -- safe-recover/path/to/tblName

The first is the fastest, which is used to fix the most common problems, and the last is the slowest, which is used to fix problems that cannot be fixed by other methods.

Check and repair MySQL Data Files

If the above method cannot repair a damaged table, you can try the following two tips before giving up:

If you suspect that the index file of the table (*. MYI) an irreparable error occurs, or even this file is lost. You can use the data file (*. MYD) and Data Format File (*. frm. Create a copy of the data file (tblName. MYD. Restart your MySQL service and connect to the service. Run the following command to delete the table content:

Mysql delete from tblName;

When deleting the table content, a new index file is created. Log out and close the service again, and overwrite the new (empty) data file with the data file (tblName. MYD) You just saved. Finally, use myisamchk to execute the standard repair (the second method above) and regenerate the index data based on the table data content and the table format file.

If your table format file (tblName. frm) is lost or an irreparable error occurs, but you know how to use the corresponding create table statement to regenerate the TABLE, you can regenerate a new one. frm files are used together with your data files and index files (if there is a problem with the index file, use the above method to recreate a new one. Create a copy of the data and index file, and then delete the original file (delete all records related to the table in the data directory ).

Start MySQL and use the original create table file to CREATE a new TABLE. The new. frm file should work properly, but you 'd better execute the Standard fix (the second method above ).

You can use a mysql statement and check table $ table; // $ table indicates the name of the data TABLE. CHECK whether the table is damaged. If the TABLE is damaged, you can use REPAIR table $ table to fix the problem. If not, it can be repaired several times more!

Introduction to modifying table structure statements in MySQL

10 common MySQL command lines

Seven common MySQL command lines

Example of MySQL statement optimized by index

Cancel MySQL user permissions

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.