Syntax
------

CHECK TABLE tbl_name [, tbl_name] ... [option] ...

option = {FOR UPGRADE | QUICK | FAST | MEDIUM | EXTENDED | CHANGED}

Description
-----------

CHECK TABLE checks a table or tables for errors. CHECK TABLE works for
Archive, Aria, CSV, InnoDB and MyISAM tables. For Aria and MyISAM tables, the
key statistics are updated as well. For CSV, see also Checking and Repairing
CSV Tables.

As an alternative, myisamchk is a commandline tool for checking MyISAM tables
when the tables are not being accessed. For Aria tables, there is a similar
tool: aria_chk.

For checking dynamic columns integrity, COLUMN_CHECK() can be used.

CHECK TABLE can also check views for problems, such as tables that are
referenced in the view definition that no longer exist.

CHECK TABLE is also supported for partitioned tables. You can use ALTER TABLE
... CHECK PARTITION to check one or more partitions.

The meaning of the different options are as follows - note that this can vary
a bit between storage engines:

+-----+----------------------------------------------------------------------+
| FOR | Do a very quick check if the storage format for the table has        |
| UPG | changed so that one needs to do a REPAIR. This is only needed when   |
| ADE | one upgrades between major versions of MariaDB or MySQL. This is     |
|     | usually done by running mysql_upgrade.                               |
+-----+----------------------------------------------------------------------+
| FAS | Only check tables that has not been closed properly or are marked    |
|     | as corrupt. Only supported by the MyISAM and Aria engines. For       |
|     | other engines the table is checked normally                          |
+-----+----------------------------------------------------------------------+
| CHA | Check only tables that has changed since last REPAIR / CHECK. Only   |
| GED | supported by the MyISAM and Aria engines. For other engines the      |
|     | table is checked normally.                                           |
+-----+----------------------------------------------------------------------+
| QUI | Do a fast check. For MyISAM and Aria, this means skipping the check  |
| K   | of the delete link chain, which may take some time.                  |
+-----+----------------------------------------------------------------------+
| MED | Scan also the data files. Checks integrity between data and index    |
| UM  | files with checksums. In most cases this should find all possible    |
|     | errors.                                                              |
+-----+----------------------------------------------------------------------+
| EXT | Does a full check to verify every possible error. For MyISAM and     |
| NDE | Aria, verify for each row that all it keys exists and points to the  |
|     | row. This may take a long time on large tables. Ignored by InnoDB    |
|     | before MariaDB 10.6.11, MariaDB 10.7.7, MariaDB 10.8.6 and MariaDB   |
|     | 10.9.4.                                                              |
+-----+----------------------------------------------------------------------+

For most cases running CHECK TABLE without options or MEDIUM should be good
enough.

The Aria storage engine supports progress reporting for this statement.

If you want to know if two tables are identical, take a look at CHECKSUM TABLE.

InnoDB
------

If CHECK TABLE finds an error in an InnoDB table, MariaDB might shutdown to
prevent the error propagation. In this case, the problem will be reported in
the error log. Otherwise the table or an index might be marked as corrupted,
to prevent use. This does not happen with some minor problems, like a wrong
number of entries in a secondary index. Those problems are reported in the
output of CHECK TABLE.

Each tablespace contains a header with metadata. This header is not checked by
this statement.

During the execution of CHECK TABLE, other threads may be blocked.

URL: https://mariadb.com/kb/en/check-table/