The index of a mysql table is damaged.

Source: Internet
Author: User
An error occurred when the index of a mysql table was damaged and solved in the afternoon. I was surprised that my dedecms website had a problem. when I visited the website, I reported an error in full screen and checked the mysql log. the error message is:

Table '. dedecmsv4de_archives' is marked as crashed and shoshould be retried Red

It indicates that the dede_archives table of cms is marked with a problem and needs to be fixed. As a result, the system quickly restored historical data and went online to find the cause. Finally, the problem is solved. The solution is as follows:

Find the bin/myisamchk tool in the mysql installation directory, and enter:

Myisamchk-c-r ../data/dedecmsv4/dede_archives.MYI

Then the myisamchk tool will help you restore the index of the data table. Restart mysql to solve the problem.

Problem analysis:

1. cause of the error. Some netizens say that the index error is caused by frequent queries and updates to the dedede_archives table. because my page is not generated statically but is a dynamic page, I agree with this statement. It is also said that the MYSQL database is damaged for some reason, such: sudden power outages on the database server and operations on the table's original files when providing services on the database table may cause damage to the MYSQL database table and the data cannot be read. In short, the table is damaged due to some unpredictable problems.

The problem number is 145.

2. solutions.

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 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 ).

3. myisamchk tool introduction (see the mysql official manual)

You can use the myisamchk utility to obtain information about database tables or to check, repair, and optimize them. Myisamchk applies to MyISAM tables (tables corresponding to. MYI and. MYD files ).

Call the myisamchk method:

Shell> myisamchk [options] tbl_name...
Options specifies what you want myisamchk to do. Describe them later. You can also obtain the option list by calling myisamchk -- help.

Tbl_name is the database table you want to check or repair. If you do not run myisamchk somewhere in the database directory, you must specify the path of the database directory because myisamchk does not know where your database is located. In fact, myisamchk does not care whether the file you are operating on is in a database directory; you can copy the file corresponding to the database table to another place and perform restoration operations there.

If you want to, you can use the myisamchk command line to name several tables. You can also specify a table by naming the index file (with the suffix ". MYI. It allows you to specify all tables in a directory by using the "*. MYI" mode. For example, if you are in the database directory, you can check all MyISAM tables in the directory as follows:

Shell> myisamchk *. MYI
If you are not in the database directory, you can check all the tables in the directory by specifying the path:

Shell> myisamchk/path/to/database_dir/*. MYI
You can even specify a wildcard for the path of the MySQL data directory to check all tables in all databases:

Shell> myisamchk/path/to/datadir/*. MYI
We recommend that you quickly check all MyISAM tables:

Shell> myisamchk -- silent -- fast/path/to/datadir/*. MYI
To check all MyISAM tables and repair any damaged tables, run the following command:

Shell> myisamchk -- silent -- force -- fast -- update-state
-O key_buffer = 64 M-O sort_buffer = 64 M
-O read_buffer = 1 M-O write_buffer = 1 M
/Path/to/datadir/*. MYI

This command assumes that you have a free memory larger than 64 MB. For more information, see section 5.9.5.5 "myisamchk memory usage ".

When running myisamchk, make sure other programs do not use tables. Otherwise, the following error message is displayed when you run myisamchk:

Warning: clients are using or haven't closed the table properly
This indicates that you are trying to check the table that is being updated by another program that has not closed the file or has been terminated but has not properly closed the file (for example, mysqld server.

If mysqld is running, you must use flush tables to forcibly clear any table that is still in memory for modification. When running myisamchk, make sure other programs do not use tables. The easiest way to avoid this problem is to use check table instead of myisamchk.

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.