通過performance schema收集慢查詢
阿新 • • 發佈:2018-01-23
慢查詢 啟用 stat count ges mysq pack 類型 https
MySQL5.6起performance schema自動開啟,裏面涉及記錄 statement event的表
mysql> show tables like ‘%statement%‘; +----------------------------------------------------+ | Tables_in_performance_schema (%statement%) | +----------------------------------------------------+ | events_statements_current | | events_statements_history | | events_statements_history_long | | events_statements_summary_by_account_by_event_name | | events_statements_summary_by_digest | | events_statements_summary_by_host_by_event_name | | events_statements_summary_by_program | | events_statements_summary_by_thread_by_event_name | | events_statements_summary_by_user_by_event_name | | events_statements_summary_global_by_event_name | | prepared_statements_instances | +----------------------------------------------------+ 11rows in set (0.00 sec)
statement event 的設置
詳細參考官方文檔:https://dev.mysql.com/doc/refman/5.6/en/performance-schema-statement-tables.ht
server端發生的所有的statement都會記錄,當前未結束的會話發生的statement記錄在表events_statements_current,已結束的會話線程發生的statement記錄在events_statements_history,此表有大小限制,默認是100,達到限制會刪除老的statement
設置記錄哪些類型的statement,默認設置為所有的類型
mysql> SELECT * FROM setup_instruments WHERE NAME LIKE ‘statement/%‘; +---------------------------------------------+---------+-------+ | NAME | ENABLED | TIMED | +---------------------------------------------+---------+-------+ | statement/sql/select |YES | YES | | statement/sql/create_table | YES | YES | | statement/sql/create_index | YES | YES | ... | statement/sp/stmt | YES | YES | | statement/sp/set | YES | YES | | statement/sp/set_trigger_field | YES | YES | | statement/scheduler/event | YES | YES | | statement/com/Sleep | YES | YES | | statement/com/Quit | YES | YES | | statement/com/Init DB | YES | YES | ... | statement/abstract/Query | YES | YES | | statement/abstract/new_packet | YES | YES | | statement/abstract/relay_log | YES | YES | +---------------------------------------------+---------+-------+
關於對statement event相關表的設置,MySQL5.6 默認events_statements_history關閉,MySQL5.7開啟
mysql> SELECT * FROM setup_consumers WHERE NAME LIKE ‘%statements%‘; +--------------------------------+---------+ | NAME | ENABLED | +--------------------------------+---------+ | events_statements_current | YES | | events_statements_history | NO | | events_statements_history_long | NO | | statements_digest | YES | +--------------------------------+---------+
如果通過pmm來收集慢查詢,其查詢的是表events_statements_history_long,MySQL5.6需要啟用此表
啟用events_statements_history
UPDATE setup_consumers SET ENABLED = ‘NO‘ WHERE NAME LIKE ‘events_statements_history‘;
通過performance schema收集慢查詢