How to repair corrupted MySQL Data Tables

Source: Internet
Author: User

MySQL database errors caused by power failure or abnormal shutdown are very common problems. There are two methods: one is to use the check table and repair table SQL statements of mysql, and the other is to use multiple myisamchk and isamchk Data Detection and recovery tools provided by MySQL. The former is easy to use. Recommended.

1. check table and repair table
Log on to the mysql terminal:
Mysql-uxxxxx-p dbname
> Check table tabTest;
If the Status is OK, you do not need to fix it. If there is an Error, you can use:
> Repair table tabTest;
After the repair, you can use the check table command to perform the check. You can also use the check/repair function in the new phpMyAdmin version.

2. myisamchk, isamchk
Here, myisamchk applies to MYISAM data tables, while isamchk applies to ISAM data tables. The main parameters of these two commands are the same. Generally, new systems use MYISAM as the default data table type. Here we use myisamchk as an example. When a problem occurs in a data table, you can use:

Myisamchk tablename. MYI

To fix the issue, use:

Myisamchk-of tablename. MYI

For detailed parameter descriptions of myisamchk, see its help. Make sure that the data table is not accessed by the MySQL server when you modify the data table. It is safe to shut down the MySQL server during detection.

-----------------------------

In addition, you can place the following command in your rc. local to start the MySQL server:

[-X/tmp/mysql. sock] & amp;/pathtochk/myisamchk-of/DATA_DIR/*. MYI

/Tmp/mysql. sock is the location of the Sock file monitored by MySQL. For RPM-based installation, it should be/var/lib/mysql. sock. For source code installation, it is/tmp/mysql. sock can be changed based on actual conditions, while pathtochk is the location where myisamchk is located, and DATA_DIR is the location where your MySQL database is stored.

Note that if you plan to place this command in your rc. local, make sure that the MySQL server is not started when executing this command!

Detection and repair of all databases (tables)
Mysqlcheck-A-o-r-p
---------------------------------------------------------------------------------


Example:
Mysql> check table tabFTPAccountInstances;

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.