How to see indexes for a database or table in MySQL

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

How about for a specific table?
Aug 18, 2020 in PHP by kartik
• 37,520 points
153,422 views

Hello @kartik,

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

SHOW INDEX FROM yourtable;

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';

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

Hope it helps!!

Thank You!!

1 answer to this question.

0 votes

Hello @kartik,

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

SHOW INDEX FROM yourtable;

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';

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

Hope it helps!!

If you need to know more about SQL , it is recommended that you go for the SQL Course.

Thank You!!

answered Aug 18, 2020 by Niroj
• 82,800 points
thanks for the answer