Solves the problem of a crash-based MySQL table maintenance process.

Source: Internet
Author: User

Some customers reported that the boss system could not query the order record after January 1, June 28. After the database was queried, the query for the original statement table occasionally appeared.
Table '****' is marked as crashed and shoshould be retried red.
After confirming that the billing is correct, I decided to perform the table repair work after work. Because no such operation was performed before, I was worried that there would be problems. I saw the information from Baidu that prompted me to restart the MySQL service after the repair.
After work, the database is completely backed up and the data table is repaired. The solution is as follows:
Shell> myisamchk-R [tablename];
When the repair operation is successful, restart MySQL takes into account the conflict between the previous MySQL restart and other services, the O & M record is about to restart the server, so reboot
After the database is connected, it is found that the database can be logged on in the localhost domain, and cannot be connected in other domains. The connection reports error 10061. Restart the MySQL service and the error message is invalid.
There is no way to recover to the status before the backup, and you can access it. But the table repaired in the previous stage is gone, and the physical file of the database is found. There is no way to solve the problem and it scared me.
I had to go to the doctor and execute table repair again. I didn't rush to restart MySQL this time. I found that the table is out and the query is normal. Everything is OK.
It seems that restarting the service is not necessary, at least this time. Fortunately, several operations have been backed up!
However, it is confusing that after the repair is executed for the first time, how can we not connect to the server after restart?>

Well, I don't understand why the table is crash. I will post the information on the White Paper for your reference:

1. Cause of the Error. Some netizens say that the index error is caused by frequent queries and table updates, and that the MySQL database is damaged for some reason, for example, sudden power outages on the database server and operations on the table's original files when providing services to 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.
2. 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.