Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Monitoring queries of a MySQL user

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.

like image 432
Maher Avatar asked Jan 03 '11 15:01

Maher


People also ask

What is MySQL query analyzer?

The MySQL Query Analyzer enables developers and DBAs to quickly improve the performance of their database applications by monitoring query performance. MySQL Query Analyzer lets you accurately pinpoint SQL code that is the root cause of a slow down.

Is there a profiler for MySQL?

Query Profiler, built into dbForge Studio for MySQL, is the best query optimization tool to tune MySQL queries and investigate query performance issues in an efficient and fast way. It helps build up a picture of how the queries are run to access data and what operations impact your application.


1 Answers

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

like image 154
Rituparna Kashyap Avatar answered Oct 04 '22 05:10

Rituparna Kashyap