I’m working with a MySQL database and need to check what indexes exist. I want to know two things:
- How do I display all indexes that are currently set up in my entire database?
- How do I check which indexes are applied to one specific table?
I’ve been trying to optimize my queries and I think looking at the existing indexes would help me understand the current setup better. Are there any MySQL commands or queries I can use to get this information? I’m using MySQL version 8.0 if that matters for the syntax.
To check indexes in MySQL, use SHOW INDEX FROM table_name; for a specific table - it’ll show you the index name, type, and other details. If you want to see all indexes across your database, run SELECT * FROM information_schema.statistics WHERE table_schema = 'your_database_name';. This provides every indexed column, which is beneficial for performance audits. Additionally, using SHOW CREATE TABLE table_name; allows you to see the complete table structure, including composite indexes, which is helpful for documenting your schema.