SHOW INDEXES [FROM|IN]

SHOW INDEXES [FROM|IN] 语句用于列出指定表上的索引。SHOW INDEX [FROM | IN]SHOW KEYS [FROM | IN] 是该语句的别名。包含该语句提供了 MySQL 兼容性。

语法图

ShowStmt:

ShowStmt

ShowTargetFilterable:

ShowTargetFilterable

ShowIndexKwd:

ShowIndexKwd

FromOrIn:

FromOrIn

TableName:

TableName

示例

  1. mysql> CREATE TABLE t1 (id int not null primary key auto_increment, col1 INT, INDEX(col1));
  2. Query OK, 0 rows affected (0.12 sec)
  3. mysql> SHOW INDEXES FROM t1;
  4. +-------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
  5. | Table | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | Index_comment |
  6. +-------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
  7. | t1 | 0 | PRIMARY | 1 | id | A | 0 | NULL | NULL | | BTREE | | |
  8. | t1 | 1 | col1 | 1 | col1 | A | 0 | NULL | NULL | YES | BTREE | | |
  9. +-------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
  10. 2 rows in set (0.00 sec)
  11. mysql> SHOW INDEX FROM t1;
  12. +-------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
  13. | Table | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | Index_comment |
  14. +-------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
  15. | t1 | 0 | PRIMARY | 1 | id | A | 0 | NULL | NULL | | BTREE | | |
  16. | t1 | 1 | col1 | 1 | col1 | A | 0 | NULL | NULL | YES | BTREE | | |
  17. +-------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
  18. 2 rows in set (0.00 sec)
  19. mysql> SHOW KEYS FROM t1;
  20. +-------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
  21. | Table | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | Index_comment |
  22. +-------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
  23. | t1 | 0 | PRIMARY | 1 | id | A | 0 | NULL | NULL | | BTREE | | |
  24. | t1 | 1 | col1 | 1 | col1 | A | 0 | NULL | NULL | YES | BTREE | | |
  25. +-------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
  26. 2 rows in set (0.00 sec)

MySQL 兼容性

SHOW INDEXES [FROM|IN] 语句与 MySQL 完全兼容。如有任何兼容性差异,请在 GitHub 上提交 issue

另请参阅