如何在 MySQL 中查看数据库或表的索引?

2021-11-20 00:00:00 indexing database-schema mysql

如何查看我的数据库是否有索引?

How do I see if my database has any indexes on it?

对于特定的表如何?

推荐答案

要查看特定表的索引,请使用 SHOW INDEX:

To see the index for a specific table use SHOW INDEX:

SHOW INDEX FROM yourtable;

要查看特定架构中所有表的索引,您可以使用 INFORMATION_SCHEMA 中的 STATISTICS 表:

To see indexes for all tables within a specific schema you can use the STATISTICS table from INFORMATION_SCHEMA:

SELECT DISTINCT
    TABLE_NAME,
    INDEX_NAME
FROM INFORMATION_SCHEMA.STATISTICS
WHERE TABLE_SCHEMA = 'your_schema';

删除 where 子句将显示所有模式中的所有索引.

Removing the where clause will show you all indexes in all schemas.

相关文章