Check table syntax-MySql database

Source: Internet
Author: User
CHECK TABLE tbl_name[,tbl_name] ... [option] ...
 
option= {QUICK | FAST | MEDIUM | EXTENDED | CHANGED}

Check whether one or more tables have errors. Check table is useful for MyISAM and InnoDB tables. For MyISAM tables, keyword statistics are updated.

Check table can also CHECK whether the view has an error. For example, the referenced TABLE in the view definition does not exist.

The check table statement returns a TABLE containing the following columns:

Column

Value

Table

Table Name

Op

Check

Msg_type

Status, error, message, or error

Msg_text

Message

Note: This statement may generate multiple rows for each table to be checked. The last row has a Msg_type status value. Msg_text should generally be OK. If you do not get OK or the table has been updated, you should usually run the repaired table. See section 5.9.4 "Table maintenance and crash recovery ". The table has been updated, which means that the table's storage engine directive does not require a checklist.

Different check options that can be given are listed in the following table. These options only apply to checking the MyISAM table. For InnoDB tables and views, these options are ignored.

Type

Meaning

Quick

The row is not scanned, and the error link is not checked.

Fast

Only the tables that are not properly closed are checked.

Changed

Only the tables modified after the last check and the tables not properly closed are checked.

Medium

Scan rows to verify that the deleted link is valid. You can also calculate the keyword checksum of each row and use the calculated checksum to verify this.

Extended

Perform a full keyword search for all the keywords in each row. This ensures that the table is 100% consistent, but it takes a long time.

If you do not specify the QUICK, MEDIUM, or EXTENDED options, the default check type for dynamic MyISAM tables is MEDIUM. This is similar to running a tableMyisamchk -- medium-checkTbl_nameThe results are the same. For MyISAM tables in static format, the default check type is MEDIUM, unless CHANGED or FAST has been specified. In this case, the default value is QUICK. For CHANGED and FAST, the row scan is skipped because the row is rarely damaged.

You can combine the check options, as shown in the following example. In this example, a quick check is performed on the table to check whether the table is disabled correctly:

CHECK TABLE test_table FAST QUICK;

Note: In some cases, check table changes the TABLE. This situation occurs if the table is marked as "writable upted" or "not closed properly. However, check table does not identify problems in the TABLE. In this case, check table marks the TABLE as good.

If a table is damaged, it is likely that the problem is in the index, not in the data section. All of the preceding checking types can thoroughly check the index, so you can identify most of the errors.

If you only want to check that the table you assumed is good, you should not use the check option or QUICK option. Use QUICK when you are in a hurry. QUICK cannot identify errors in data files. (In most cases, MySQL should be able to identify errors in data files during normal use. If an error is found, the table is marked as "successfully upted" and cannot be used until it is fixed .)

If you want to check tables from time to time, FAST and CHANGED are mostly used from the original (for example, executed from cron ). In most cases, FAST takes precedence over CHANGED. (In only one case, FAST does not take precedence over CHANGED, that is, when you suspect that you have found an error in MyISAM code .)

When MySQL tries to update a row or search for a row by using the keyword, EXTENDED is used if you have run a regular check but still get a strange error from the table. (EXTENDED is not required if the regular check runs successfully .)

Some issues reported by check table will not be automatically corrected:

? Row found. In this row, the auto_increment column has a value of 0.

This means that you have a row in the table, and the AUTO_INCREMENT index column of the row contains 0 values. (You can use the UPDATE statement to explicitly set the column to 0 to create a row with the AUTO_INCREMENT column as 0 .)

This is not an error, but if you decide to dump the TABLE and restore the TABLE, or ALTER the TABLE, it will cause trouble. In this case, the AUTO_INCREMENT column changes the value based on the result of the AUTO_INCREMENT column, which leads to problems, such as duplicate keyword errors.

To eliminate the warning, you only need to execute an UPDATE statement and set the column to a value other than 0.

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.