CHECK TABLE

Updated at:
Copy as MD

CHECK TABLE checks a table for errors — particularly tables that failed to be created by a DDL statement.

How it works

The behavior of CHECK TABLE depends on whether the target table is sharded.

Table typeCheck performed
Sharded tableWhether all underlying physical table shards exist, and whether the columns and indexes of each shard are consistent
Single-database non-sharded tableWhether the table exists

Syntax

CHECK TABLE tbl_name

Output columns

CHECK TABLE returns a result set with the following columns.

ColumnDescription
TABLEThe fully qualified table name, in the format schema.table_name
OPThe operation type. Always check
MSG_TYPEThe message type: status indicates the final result; Error indicates the check failed
MSG_TEXTThe result message. OK indicates the check passed

Examples

Successful check — the table exists and all shards are consistent:

mysql>  check table tddl_mgr_log;
+------------------------+-------+----------+----------+
| TABLE                  | OP    | MSG_TYPE | MSG_TEXT |
+------------------------+-------+----------+----------+
| TDDL5_APP.tddl_mgr_log | check | status   | OK       |
+------------------------+-------+----------+----------+
1 row in set (0.56 sec)

Failed check — the table does not exist:

mysql> check table tddl_mg;
+-------------------+-------+----------+----------------------------------------+
| TABLE             | OP    | MSG_TYPE | MSG_TEXT                               |
+-------------------+-------+----------+----------------------------------------+
| TDDL5_APP.tddl_mg | check | Error    | Table 'tddl5_00.tddl_mg' doesn't exist |
+-------------------+-------+----------+----------------------------------------+
1 row in set (0.02 sec)