title: ADMIN CHECKSUM TABLE summary: TiDB 数据库中 ADMIN CHECKSUM TABLE 的使用概况。

ADMIN CHECKSUM TABLE

ADMIN CHECKSUM TABLE 语句用于计算表中所有行和索引的 CRC64 校验和。在 TiDB Lightning 等程序中,可通过此语句来确保导入操作成功。

语法图

  1. AdminStmt ::=
  2. 'ADMIN' ( 'SHOW' ( 'DDL' ( 'JOBS' Int64Num? WhereClauseOptional | 'JOB' 'QUERIES' NumList )? | TableName 'NEXT_ROW_ID' | 'SLOW' AdminShowSlow ) | 'CHECK' ( 'TABLE' TableNameList | 'INDEX' TableName Identifier ( HandleRange ( ',' HandleRange )* )? ) | 'RECOVER' 'INDEX' TableName Identifier | 'CLEANUP' ( 'INDEX' TableName Identifier | 'TABLE' 'LOCK' TableNameList ) | 'CHECKSUM' 'TABLE' TableNameList | 'CANCEL' 'DDL' 'JOBS' NumList | 'RELOAD' ( 'EXPR_PUSHDOWN_BLACKLIST' | 'OPT_RULE_BLACKLIST' | 'BINDINGS' ) | 'PLUGINS' ( 'ENABLE' | 'DISABLE' ) PluginNameList | 'REPAIR' 'TABLE' TableName CreateTableStmt | ( 'FLUSH' | 'CAPTURE' | 'EVOLVE' ) 'BINDINGS' )
  3. TableNameList ::=
  4. TableName ( ',' TableName )*

示例

计算表 t1 的校验和:

  1. CREATE TABLE t1 (id INT NOT NULL PRIMARY KEY auto_increment);
  2. INSERT INTO t1 VALUES (1),(2),(3);
  3. ADMIN CHECKSUM TABLE t1;
  1. CREATE TABLE t1 (id INT NOT NULL PRIMARY KEY auto_increment);
  2. Query OK, 0 rows affected (0.11 sec)
  3. INSERT INTO t1 VALUES (1),(2),(3);
  4. Query OK, 3 rows affected (0.02 sec)
  5. Records: 3 Duplicates: 0 Warnings: 0
  6. ADMIN CHECKSUM TABLE t1;
  7. +---------+------------+----------------------+-----------+-------------+
  8. | Db_name | Table_name | Checksum_crc64_xor | Total_kvs | Total_bytes |
  9. +---------+------------+----------------------+-----------+-------------+
  10. | test | t1 | 10909174369497628533 | 3 | 75 |
  11. +---------+------------+----------------------+-----------+-------------+
  12. 1 row in set (0.00 sec)

MySQL 兼容性

ADMIN CHECKSUM TABLE 语句是 TiDB 对 MySQL 语法的扩展。