我在我的Ubuntu 14.04上运行了MySQL 5.6.19社区服务器。最近我一直在尝试使用performance_schema来监控MySQL服务器。以前我曾经通过使用cronjob每5秒运行一次SHOW FULL PROCESSLIST查询来做到这一点。
我按如下方式配置了 performance_schema.setup_consumers 表。
mysql> use performance_schema;
mysql> select * from setup_consumers;
+--------------------------------+---------+
| NAME | ENABLED |
+--------------------------------+---------+
| events_stages_current | NO |
| events_stages_history | NO |
| events_stages_history_long | NO |
| events_statements_current | YES |
| events_statements_history | NO |
| events_statements_history_long | NO |
| events_waits_current | NO |
| events_waits_history | NO |
| events_waits_history_long | NO |
| global_instrumentation | YES |
| thread_instrumentation | YES |
| statements_digest | YES |
+--------------------------------+---------+
默认情况下, events_statements_history 未启用。我按如下方式启用了它。
mysql> update setup_consumers set enabled="YES" where name="events_statements_history";
Query OK, 1 row affected (0.01 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> select * from setup_consumers;
+--------------------------------+---------+
| NAME | ENABLED |
+--------------------------------+---------+
| events_stages_current | NO |
| events_stages_history | NO |
| events_stages_history_long | NO |
| events_statements_current | YES |
| events_statements_history | YES |
| events_statements_history_long | NO |
| events_waits_current | NO |
| events_waits_history | NO |
| events_waits_history_long | NO |
| global_instrumentation | YES |
| thread_instrumentation | YES |
| statements_digest | YES |
+--------------------------------+---------+
现在已启用, events_statements_history 表现在应该能够捕获查询,但不知道它不是。以下是结果。
mysql> select count(sql_text) from events_statements_history;
+-----------------+
| count(sql_text) |
+-----------------+
| 0 |
+-----------------+
我不明白为什么它没有登录任何查询?
答案 0 :(得分:2)
性能模式在满足三个条件时记录数据:
默认情况下,每个线程(1)都经过检测。
检查线程是否已检测:
select THREAD_ID, NAME, PROCESSLIST_ID, PROCESSLIST_USER, PROCESSLIST_HOST, INSTRUMENTED from threads;
要更改默认情况下要检测的线程,请使用表setup_actors。
默认情况下,语句(aka,查询)的工具已启用(2)。
要查看未检测的查询:
select * from setup_instruments where name like "statement/%" and enabled='NO';
检测所有查询:
update setup_instruments set enabled="YES" where name like "statement/%";
默认情况下,只有少数消费者可以使用(3)。
要查看已检测的消费者或更改此消费者,请在表setup_consumers上使用select / update。
这个部分似乎没问题,所以检查第(1)和(2)部分。
答案 1 :(得分:0)
作为旁注,如果setup_%
表中没有任何内容,那么您可能需要启用性能模式,
https://dev.mysql.com/doc/refman/5.5/en/performance-schema-quick-start.html