I went to work in the afternoon and was shocked to hear that there was a problem with my dedecms website. When I visited it, I found a full-screen error. I checked the mysql log and the error message was:
Table '.dedecmsv4dede_archives' is marked as crashed and should be repaired.
It says cms. The article table dede_archives is marked as problematic and needs to be repaired. So I quickly restored the historical data and went online to find out the cause. The problem will eventually be solved. The solution is as follows:
Find the bin/myisamchk tool in the mysql installation directory, and enter in the command line:
myisamchk -c -r ../data/dedecmsv4/dede_archives.MYI
Then the myisamchk tool will help you restore the index of the data table. Restart mysql and the problem is solved.
Problem analysis:
1. The cause of the error. Some netizens said that it was an index error caused by frequent querying and updating of the dede_archives table. Because my page was not statically generated, but a dynamic page, I quite agree with this statement. It is also said that the MYSQL database has been damaged for some reason. For example, a sudden power outage of the database server, some operation on the original file of the table when providing services to the database table may cause the MYSQL database to be damaged. The table is corrupted and the data cannot be read. In short, the watch is damaged due to some unfathomable problems.
The problem number is 145
2. Solution to the problem.
When you try to repair a corrupted table problem, there are three types of repairs. If you get an error message stating that a temporary file cannot be created, delete the file indicated by the message and try again - this is usually a holdover from a previous repair operation.
The three fixes 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 and is used to fix the most common problems; the last is the slowest and is used to fix problems that cannot be fixed by other methods.
Checking and Repairing MySQL Data Files If the above methods cannot repair a damaged table, before you give up, you can also try these two tips:
If you suspect that an irreparable error has occurred in the index file (*.MYI) of the table, or even the file is lost, you can use the data file (*.MYD) and data format file (*.frm) to regenerate it. First make a copy of the data file (tblName.MYD). Restart your MySQL service and connect to it. Use the following command to delete the contents of the table:
mysql> DELETE FROM tblName;
While deleting the contents of the table, a new index file will be created. Log out and close the service again, then overwrite the new (empty) data file with the data file you just saved (tblName.MYD). Finally, use myisamchk to perform a standard repair (the second method above) to regenerate the index data based on the contents of the table's data and the table's format file.
If your table's format file (tblName.frm) is missing or has an irreparable error, but you know how to use the corresponding CREATE TABLE statement to regenerate the table, you can regenerate a new .frm file. And use it with your data files and index files (if there is a problem with the index file, use the method above to rebuild a new one). First make a copy of the data and index files, and then delete the original files (delete all records related to this table in the data directory).
Start the MySQL service and create a new table using the original CREATE TABLE file. The new .frm file should work fine, but it's best if you perform a standard repair (the second method above).
3. Introduction to the myisamchk tool (see the official manual of mysql).
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).
Method to call myisamchk:
shell> myisamchk [options] tbl_name ...
options specifies what you want myisamchk to do. They are described later. You can also get a list of options 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 to 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 located in a database directory; you can copy the file corresponding to the database table elsewhere and perform the restore operation there.
If you wish, you can use the myisamchk command line to name several tables. You can also specify a table by naming the index file (with a ".MYI" suffix). It allows you to specify all tables in a directory by using the schema "*.MYI". For example, if you are in the database directory, you can check all MyISAM tables in the directory like this:
shell> myisamchk *.MYI
If you are not in the database directory, you can check all tables there by specifying the path to the directory:
shell> myisamchk /path/to/database_dir/*.MYI
You can even check all tables in all databases by specifying a wildcard for the path to the MySQL data directory:
shell> myisamchk /path/to/datadir/*/*.MYI
The recommended way to quickly check all MyISAM tables is:
shell> myisamchk --silent --fast /path/to/datadir/*/*.MYI
If you want to check all MyISAM tables and repair any corrupted tables, you can use 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 you have more than 64MB of free memory. For details on allocating memory with myisamchk, see Section 5.9.5.5, “myisamchk Memory Usage”.
When you run myisamchk, you must ensure that other programs are not using the table. Otherwise, when you run myisamchk, the following error message will be displayed:
warning: clients are using or haven't closed the table properly
This indicates that you are trying to check a table that is being updated by another program (such as the mysqld server) that has not closed the file or has terminated without closing the file properly.
If mysqld is running, you must force flush any table modifications still in memory via FLUSH TABLES. When you run myisamchk, you must ensure that other programs are not using the table. The easiest way to avoid the problem is to use CHECK TABLE instead of myisamchk to check the table.