如何查看实时MySQL查询? [英] How can I view live MySQL queries?

查看:138
本文介绍了如何查看实时MySQL查询?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在Linux服务器上跟踪MySQL查询?

How can I trace MySQL queries on my Linux server as they happen?

例如,我希望设置某种侦听器,然后请求一个网页并查看引擎执行的所有查询,或者仅查看在生产服务器上运行的所有查询.我该怎么办?

For example I'd love to set up some sort of listener, then request a web page and view all of the queries the engine executed, or just view all of the queries being run on a production server. How can I do this?

推荐答案

您可以运行MySQL命令SHOW FULL PROCESSLIST;来查看在任何给定时间正在处理哪些查询,但这可能无法实现您希望的

You can run the MySQL command SHOW FULL PROCESSLIST; to see what queries are being processed at any given time, but that probably won't achieve what you're hoping for.

获取历史记录而不必使用服务器修改每个应用程序的最佳方法可能是通过触发器.您可以设置触发器,以便每次查询运行都会将查询插入某种历史记录表中,然后创建一个单独的页面来访问此信息.

The best method to get a history without having to modify every application using the server is probably through triggers. You could set up triggers so that every query run results in the query being inserted into some sort of history table, and then create a separate page to access this information.

请注意,这可能会大大减慢服务器上的所有内容,在每个查询的顶部添加一个额外的INSERT.

Do be aware that this will probably considerably slow down everything on the server though, with adding an extra INSERT on top of every single query.

另一种替代方法是常规查询日志,但是将其写入平面文件将消除显示灵活性的许多可能性,尤其是实时显示.如果您只是想以一种简单,易于实现的方式查看正在发生的情况,则启用GQL,然后在日志文件上使用运行tail -f即可解决问题.

another alternative is the General Query Log, but having it written to a flat file would remove a lot of possibilities for flexibility of displaying, especially in real-time. If you just want a simple, easy-to-implement way to see what's going on though, enabling the GQL and then using running tail -f on the logfile would do the trick.

这篇关于如何查看实时MySQL查询?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆