Monitoring queries of a MySQL user

一世执手 提交于 2019-12-05 03:50:30

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.

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.

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!