Search code examples
mysqlindexingdatabase-schema

How to see indexes for a database or table in MySQL?


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

How about for a specific table?


Solution

  • 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.