How to monitor sql query in mysql?


mysql logoMonitor what sql query is running in mysql is very import for performance analysis. By monitor sql query, you are be able to know what is running at the backend. if your framework logs all sql queries then you can monitor from there, if not, you might need to turn on mysql log to monitor all the sql query being executed.

To monitor sql query in MySQL, simply follow the steps below:-

Advertisements

  • Open your MySQL configuration file, normally it located at /etc/mysql/my.cnf
  • Look for a this line
    # log=/var/log/mysql/mysql.log
  • remove the # and save the file
    log=/var/log/mysql/mysql.log
  • Now, restart your mysql server to take immediate effect
    $ /etc/init.d/mysql restart
  • To monitor sql query real time, you may use this command
    $ tail -f /var/log/mysql/mysql.log

    Once you run this command, it will show the last executed message being added to the log file, so you will be able to see all the sql query that is being executed.

*** Note: After you turn on the logging, it will slow down the mysql performance. Try to do this in development server and NOT IN PRODUCTION server ***




Share this with your friends:-

One Response to “How to monitor sql query in mysql?”

  1. Glenn McKay says:

    MONyog- https://www.webyog.com/product/monyog is a very good monitoring tool for MySQL server. I am using it’s Real-Time and Query Analyzer feature to find out problem SQL and later optimize them to improve performance.

Leave a Reply