MySQL中的SHOW INDEX,SHOW INDEXES和SHOW KEYS之间的区别?

show index,show index和show key之间没有区别。它们具有相似的含义。

让我们首先创建一个表-

create table DemoTable1549
   -> (
   -> EmployeeId int NOT NULL AUTO_INCREMENT PRIMARY KEY,
   -> EmployeeName varchar(20)
   -> );

以下是创建索引的查询-

create index name_index1 on DemoTable1549(EmployeeName);
Records: 0  Duplicates: 0  Warnings: 0

以下是查询SHOW INDEX-

show index from DemoTable1549;

这将产生以下输出-

+---------------+------------+-------------+--------------+--------------+-----------+-------------+----------+--------+------+------------+---------+---------------+---------+
| Table         | Non_unique | Key_name    | Seq_in_index | Column_name  | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | Index_comment | Visible |
+---------------+------------+-------------+--------------+--------------+-----------+-------------+----------+--------+------+------------+---------+---------------+---------+
| demotable1549 |          0 | PRIMARY     |            1 | EmployeeId   |         A |           0 |     NULL |   NULL |      | BTREE      |         |               |     YES |
| demotable1549 |          1 | name_index1 |            1 | EmployeeName |         A |           0 |     NULL |   NULL |  YES | BTREE      |         |               |     YES |
+---------------+------------+-------------+--------------+--------------+-----------+-------------+----------+--------+------+------------+---------+---------------+---------+
2 rows in set (0.17 sec)

这是SHOW INDEXES的查询-

show indexes from DemoTable1549;

这将产生以下输出-

+---------------+------------+-------------+--------------+--------------+-----------+-------------+----------+--------+------+------------+---------+---------------+---------+
| Table         | Non_unique | Key_name    | Seq_in_index | Column_name  | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | Index_comment | Visible |
+---------------+------------+-------------+--------------+--------------+-----------+-------------+----------+--------+------+------------+---------+---------------+---------+
| demotable1549 |          0 | PRIMARY     |            1 | EmployeeId   |         A |           0 |     NULL |   NULL |      | BTREE      |         |               |     YES |
| demotable1549 |          1 | name_index1 |            1 | EmployeeName |         A |           0 |     NULL |   NULL | YES  | BTREE      |         |               |     YES |
+---------------+------------+-------------+--------------+--------------+-----------+-------------+----------+--------+------+------------+---------+---------------+---------+
2 rows in set (0.00 sec)

这是实现SHOW KEYS的查询-

show keys from DemoTable1549;

这将产生以下输出-

+---------------+------------+-------------+--------------+--------------+-----------+-------------+----------+--------+------+------------+---------+---------------+---------+
| Table         | Non_unique | Key_name    | Seq_in_index | Column_name  | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | Index_comment | Visible |
+---------------+------------+-------------+--------------+--------------+-----------+-------------+----------+--------+------+------------+---------+---------------+---------+
| demotable1549 |          0 | PRIMARY     |            1 | EmployeeId   |         A |           0 |     NULL | NULL   |      | BTREE      |         |               |     YES |
| demotable1549 |          1 | name_index1 |            1 | EmployeeName |         A |           0 |     NULL | NULL   | YES  | BTREE      |         |               |     YES |
+---------------+------------+-------------+--------------+--------------+-----------+-------------+----------+--------+------+------------+---------+---------------+---------+
2 rows in set (0.00 sec)