How to deal with the destruction of MySQL table Indexes

Source: Internet
Author: User

This article mainly describes the actual solution to the destruction of MySQL table indexes, I saw information about the actual solution to MySQL table index destruction on the relevant website two days ago. I will share it with you today, hoping to help you in this regard.

When I went to work in the afternoon, I heard that my dedecms website had a problem. I checked the full screen error and checked the MySQL (the best combination with PHP) log. The error message is:

 
 
  1. Table '.\dedecmsv4\dede_archives' is marked as crashed and should be repaired 

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 installation directory of MySQL (the best combination with PHP), and enter:

 
 
  1. myisamchk -c -r ../data/dedecmsv4/dede_archives.MYI 

Then, the myisamchk tool will help you restore the MySQL table index. Restart MySQL (the best combination with PHP) to solve the problem.

Problem Analysis:

1. Cause of errorSome netizens say that the index error caused by frequent queries and updates to the dede_archives table is because my page is not generated statically but is a dynamic page. Therefore, I agree with this statement. It is also said that the MySQL database (the best combination with PHP) is damaged for some reason, such: sudden Power outages on the database server and operations on the original table files when providing services on the database table may lead to MySQL (the best combination with PHP) the database table is damaged and cannot read data. 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:

 
 
  1. % myisamchk --recover --quick /path/to/tblName   
  2. % myisamchk --recover /path/to/tblName   
  3. % 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 fix MySQL (the best combination with PHP) data files. If the above method cannot repair a corrupted table, you can try the following two tips before giving up:

If you suspect that the MySQL table index file (*. 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 (the best combination with PHP) service and connect to the service. Run the following command to delete the table content:

 
 
  1. MySQL (best combination with PHP)> 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 (the best combination with PHP) service 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. For details about the myisamchk tool, see the official MySQL (best combination with PHP) 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:

 
 
  1. 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 MySQL table 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:

 
 
  1. shell> myisamchk *.MYI 

If you are not in the database directory, you can check all the tables in the directory by specifying the path:

 
 
  1. shell> myisamchk /path/to/database_dir/*.MYI 

You can even specify a wildcard for the path of the Data Directory of MySQL (the best combination with PHP) to check all tables in all databases:

 
 
  1. shell> myisamchk /path/to/datadir/*/*.MYI 

We recommend that you quickly check all MyISAM tables:

 
 
  1. shell> myisamchk --silent --fast /path/to/datadir/*/*.MYI 

To check all MyISAM tables and repair any damaged tables, run the following command:

 
 
  1. shell> myisamchk --silent --force --fast --update-state \  
  2. -O key_buffer=64M -O sort_buffer=64M \  
  3. -O read_buffer=1M -O write_buffer=1M \  
  4. /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:

 
 
  1. warning: clients are using or haven't closed the table properly 

This indicates that you are trying to check that the file is being closed by another program that has not closed the file or is terminated but has not properly closed the file (for example, MySQL (the best combination with PHP) d server) the updated table.

If MySQL (the best combination with PHP) d 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.

The above content is an introduction to the problem of damage to the index of a MySQL table and the solution. I hope you will get some benefits.

498) this. style. width = 498; "/>

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.