How to detect MySQL database table faults

Source: Internet
Author: User
Welcome to the Linux community forum and interact with 2 million technical staff. When you use MySQL, unexpected damage to the database table may occur, and the data is often the latest, it is generally not possible to find the data in the backup. This article describes how to detect MySQL database table faults. The general process of fault detection and correction in the table is as follows:

Welcome to the Linux community forum and interact with 2 million technical staff> when you are using MySQL, unexpected damage to the database table may occur, and the data is often the latest, it is generally not possible to find the data in the backup. This article describes how to detect MySQL database table faults. The general process of fault detection and correction in the table is as follows:

Welcome to the Linux community forum and interact with 2 million technicians>

When using MySQL, you may encounter various unexpected damages to the database table, and the data is often the latest and cannot be found in the backup data. This article describes how to detect MySQL database table faults.

The general process of fault detection and correction in the table is as follows:

◆ Check tables with errors. If the table check is successful, the task is completed. Otherwise, the database table with errors must be repaired.

◆ Copy the table file before starting the restoration to ensure data security.

◆ Start restoring database tables.

◆ If the restoration fails, recover data from the database backup or update log.

Before using myisamchk or isamchk to check or repair a table, note the following:

◆ Create database backup and use update logs to prevent repair failures and data loss.

◆ Read this chapter carefully before proceeding with the operation, especially before reading "Avoid interacting with MySQL Server. Because it may cause serious consequences if you do not have enough knowledge.

◆ If you maintain a table on the Unix platform, you should first register a dedicated account mysql to avoid ownership issues during table read/write access and damage all permissions of the database directory.

Database Table maintenance tools

MySQL's myisanchk and isamchk utilities are similar, basically they have the same usage method. The type of the table used for the main differences between them. To check/fix MyISAM tables (. MYI and. MYD), you should use the myisamchk utility. To check/repair ISAM tables (. ISM and. ISD), you should use the isamchk utility.

◆ To use any program, specify the table you want to check or repair. The usage of myisamchk and isamchk is as follows:

Shell> myisamchk options tbl_nameshell> isamchk options tbl_name

If you want to, you can name several tables in the command line.

◆ You can also specify a name as an index file (". MYI "or". ISM), which allows you to use the mode "*. MYI "or". ISM specifies all tables in a directory. For example, if you are in a database directory, you can check all tables in the directory as follows:

Shell> myisamchk *. MYIshell> isamchk *. ISM

◆ If you are not in the database directory, you can specify the directory path:

Shell> myisamchk options/path/to/database_dir/*. MYIshell> isamchk options/path/to/database_dir/*. ISM

◆ You can even specify a wildcard for the path of the MySQL data directory to act on all tables in all databases:

Shell> myisamchk options/path/to/datadir/*. MYIshell> isamchk options/path/to/database_dir/*. ISM

This method cannot be used on windows.

Note that neither myisamchk nor isamchk can determine the location of the table. Therefore, you should run the program in the directory containing the table file or specify the table path name. This allows you to copy the table file to another directory and use the copy operation.

Check database tables

Myisamchk and isamchk provide table check methods that differ in the extent to which a thorough checklist is performed.

Standard Method Checklist

Generally, the standard method is enough. Check the table using a standard method. You can directly call the table without any options, or use either the-s or -- silent options:

Myisamchk tbl_nameisamchk tbl_name

This can identify the 99.99% of all errors. What it cannot find is that it only involves corruption of data files (which is not common ).

Complete and thorough data check

To perform the expansion check, use the -- extend-check or-e option, which checks the data:

Myisamchk-e tbl_nameisamchk-e tbl_name

It performs a completely thorough data check (-e means "extension check "). It performs a read check on each row for each key to verify that they actually point to the correct row. This can take a long time on a large table with many keys. Myisamchk usually stops after it discovers the first error. If you want more information, you can add the -- verbose (-v) option. This causes the myisamchk or isamchk to continue up to 20 errors. In general use, a simple standard check (without parameters other than the table name) is enough.

Moderate check

Specify options -- medium-check or-m

Myisamchk-m tbl_name

A moderate check is not as fast as a full extension check. It is of little significance and rarely used.

If no error is reported for the -- extend-check, the table is intact. If you still feel that the table is faulty, the reason must be somewhere else. Re-check and queries that appear to be problematic to verify that the query is correctly written. If you think the problem may be caused by the MySQL server, you should organize a fault report or upgrade it to a new version.

Possible check options:

1.-I or-information: Print statistical information, for example:

Myisamchk-e-I tbl_name

Like the previous command, the-I option tells myisamchk to print some statistics.

2.-C, -- check-only-changed

Only the tables modified after the last check are checked.

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.