The following articles mainly describe the problems arising from the destruction of a MySQL index and their actual solutions. If you are interested in the actual operation scheme, you can browse the following articles. The following describes the specific content of the article.
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:
- 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:
- myisamchk -c -r ../data/dedecmsv4/dede_archives.MYI
Then the myisamchk tool will help you restore the MySQL index of the data table. Restart MySQL (the best combination with PHP) to solve the problem.
Problem Analysis:
1. The cause of the error was described by some netizens as the MySQL index error 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 (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:
- % 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 fix MySQL (best combination with PHP) 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 MySQL 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 (the best combination with PHP) service and connect to the service. Run the following command to delete the table content:
- 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 file and use it with your data file and index file (if there is a problem with the MySQL index file, use the method above 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:
- 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 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 Data Directory of MySQL (the best combination with PHP) 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=64M -O sort_buffer=64M \
- -O read_buffer=1M -O write_buffer=1M \
- /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 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 that the MySQL index is damaged and the solution. I hope you will get some benefits.