What is MySQL's performance schema?

Answer

The Performance Schema (P_S) is a built-in MySQL database (performance_schema) that provides a low-level monitoring capability for MySQL server execution. It instruments server internals to collect performance data with minimal overhead. Enabled by default in MySQL 5.6+. Key tables: events_statements_* — SQL statement statistics (total time, rows examined, temporary tables); events_stages_* — internal processing stages per statement; events_waits_* — wait events (mutex waits, I/O waits, lock waits); table_io_waits_summary_by_table — I/O activity per table; table_lock_waits_summary_by_table — lock waits per table; file_summary_by_event_name — file I/O. Useful queries: find top slow queries: SELECT DIGEST_TEXT, AVG_TIMER_WAIT/1e12 AS avg_sec, COUNT_STAR FROM performance_schema.events_statements_summary_by_digest ORDER BY avg_sec DESC LIMIT 10;. The sys schema (MySQL 5.7.7+) provides user-friendly views on top of performance_schema: SELECT * FROM sys.statements_with_full_table_scans ORDER BY no_index_used_count DESC;. Enable specific instruments: UPDATE performance_schema.setup_instruments SET ENABLED="YES" WHERE NAME LIKE "statement/%";