监控MySQL用户的查询

发布于 2024-10-10 06:57:57 字数 234 浏览 0 评论 0原文

有什么方法可以监控/记录 MySQL 用户和他/她运行的查询吗?我必须使用查询关闭常规日志:

SET GLOBAL general_log = 'OFF';  

因为否则文本编辑器将无法再处理日志文件。我一直在寻找一种方法来为我想要监视的某些用户打开此日志,但它似乎不起作用。

有没有其他方法可以了解某个特定用户在我的数据库上运行的所有内容?

提前致谢。

is there any way to monitor/log a MySQL user and the queries he/she has ran? I had to turn off the general log using the query:

SET GLOBAL general_log = 'OFF';  

because otherwise the log file was no more processable by text editors. I was looking for a way to turn this log on for some users I want to monitor, but it does not seem to work that way.

Is there any other way to know everything a definite user does run on my database?

Thanks in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

溺ぐ爱和你が 2024-10-17 06:57:57

我可以建议几种方法。

  1. SELECT * FROM information_schema.PROCESSLIST WHERE USER="someuser"; 现在由您决定使用什么。编写一个 cronjob (linux) 将其存储到文件中,或编写一个 MySQL 事件将其输入到 mysql 表中。
  2. 使用常规查询日志并使用linux awk、sed、grep等工具解析日志文件以获得理想的结果

但是如果您不习惯编写命令行linux命令,您可以使用mk-query-digest甚至可以配置自定义监控工具,例如nagioscacti等。但我个人更喜欢MONyog,它完美地完成了第 1 点和第 2 点,最重要的是它有一个 GUI。

在此处输入图像描述

There are a few ways I can suggest.

  1. SELECT * FROM information_schema.PROCESSLIST WHERE USER="someuser"; Now it is up to you what you use. Write a cronjob (linux) to store it into a file or write a MySQL event to enter it into a mysql table.
  2. Use General query log and use tools like linux awk, sed, grep etc to parse the log file to get desirable result

But if you are not accustom in writing command line linux command you can use mk-query-digest or even can configure custom monitoring tools like nagios, cacti etc. But I personally prefer MONyog, it does both point 1 and 2 perfectly and best of all it has a GUI.

enter image description here

箹锭⒈辈孓 2024-10-17 06:57:57

日志管理详细信息

MySQL 服务器可以创建许多不同的日志文件来帮助您查看正在发生的活动。请参见第 5.2 节“MySQL 服务器日志”。但是,您必须定期清理这些文件,以确保日志不会占用过多的磁盘空间


在其他系统上,您必须自己安装一个从 cron(或其等效项)启动的简短脚本来处理日志文件。


您可以通过刷新日志来强制 MySQL 开始使用新的日志文件。当您发出 FLUSH LOGS 语句或执行 mysqladminlush-logs、mysqladminrefresh、mysqldump --flush-logs 或 mysqldump --master-data 命令时,会发生日志刷新。

details on logging administration

MySQL Server can create a number of different log files to help you see what activity is taking place. See Section 5.2, “MySQL Server Logs”. However, you must clean up these files regularly to ensure that the logs do not take up too much disk space.


On other systems, you must install a short script yourself that you start from cron (or its equivalent) for handling log files.


You can force MySQL to start using new log files by flushing the logs. Log flushing occurs when you issue a FLUSH LOGS statement or execute a mysqladmin flush-logs, mysqladmin refresh, mysqldump --flush-logs, or mysqldump --master-data command.

余罪 2024-10-17 06:57:57

看一下 maatkit 中的 mk-query-digest 工具,它也许可以做与你想要的类似的事情。至少,如果您必须再次启用它,它应该能够帮助您解析一般查询日志:

http://www.maatkit.org/doc/mk-query-digest.html

Take a look at the mk-query-digest tool from maatkit, it may be able to do something similar to what you want. At the very least, it should be able to help you parse the general query log if you have to enable it again:

http://www.maatkit.org/doc/mk-query-digest.html

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文