dataiotech Labs
dbaguidedbaguideDBAdataxtoolsdataopsphere
Scripts Library/mysql/#24
Script #24
mysql
Performanceread-onlyMin Version: 5.7

Detect Unused Indexes in MySQL

Uses sys.schema_unused_indexes to list indexes that were never used. Helps safely drop indexes that slow down writes.

#index#unused-index#sys-schema
mysql · sql
SELECT object_schema, object_name, index_name
FROM sys.schema_unused_indexes
WHERE object_schema NOT IN ('mysql','sys','performance_schema')
ORDER BY object_schema, object_name;
Operational Notes & Remediation Guidance

Statistics reset on server reboot. Ensure sufficient uptime before safely dropping indexes.

Production Safety & Execution Standards
  • This script is designed for read-only diagnostics; it does not alter schema or modify data directly.
  • Prior to executing on production systems under high load, verify the target database version (Min. Version: 5.7).
  • Exercise caution with mutating actions (e.g., terminating sessions or dropping indexes) referenced in the notes section.