我正在运行一个简单的bash脚本,该脚本从文件中读取select语句并执行查询,以便可以收集查询的性能统计信息。

while read -r line || [[ -n $line ]]; do
    echo ${line//\\n/ }
    mysql ${MYSQL_CONN} -ANe"${line//\\n/ }" > select-output.txt 2>&1
done < ./test-stmts.txt


当我运行脚本时,查询已成功执行,但没有记录到performance_schema.events_statement_current表或performance_schema.events_statement_history表中。当我从MySQL Workbench执行相同的查询时,该查询将同时在events_statement_current表和events_statement_history表中捕获。

启用了performance_schema并也启用了相应的使用者:

events_statements_current   YES
events_statements_history   YES
events_statements_history_long  NO
statements_digest   YES


运行SHOW VARIABLES就像'performance_schema';从我的脚本返回Performance_schema ON。

我需要在脚本中添加一些内容,以便查询记录到performance_schema吗?

谢谢

最佳答案

我建议您验证是否已启用适当的性能模式参与者,以防正在运行具有Performance_schema.setup_actors表中未启用的凭据的bash脚本(通过Workbench连接到MySQL时有所不同)。

要查看启用了哪些角色,请使用:SELECT * FROM performance_schema.setup_actors;

可以在here中找到有关如何启用不同用户的更多详细信息和说明(假设您使用的是MySQL 5.7)。

尽管根据您的描述不太可能,但我相信performance_schema.setup_objects表的特定配置也会导致您描述的问题。因此,您可能还需要检查SELECT * FROM performance_schema.setup_objects;

10-05 20:28
查看更多