SHOW INDEX FROM table_name;
其中,table_name是要查看索引的表名。此命令将显示表的所有索引及其结构,如下所示:
+-------------+------------+---------------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+ | Table | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | +-------------+------------+---------------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+ | user | 0 | PRIMARY | 1 | id | A | 4 | NULL | NULL | | BTREE | | | user | 1 | username | 1 | username | A | 4 | NULL | NULL | YES | BTREE | | | user | 1 | email | 1 | email | A | 4 | NULL | NULL | YES | BTREE | | | user | 1 | password_reset_code | 1 | email | A | 4 | NULL | NULL | YES | BTREE | | +-------------+------------+---------------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+
其中,每一行代表一个表索引,显示了索引名、索引类型、索引字段等信息。
另外,可以通过以下方法查看某个索引的详细信息:
EXPLAIN SELECT * FROM table_name WHERE index_column = value;
其中,table_name是要查看索引的表名,index_column是索引字段名,value是要查找的键值。此命令将显示此查询的执行计划,包括使用的索引等信息。如果查询使用索引,则说明该索引在查询中发挥了作用。