Monitor SQL Queries in MySQL

Microsoft’s SQL Server has a tool called Profiler that you can use to monitor every SQL query that hits the database. This is extremely useful for programmers as well as database administrators to troubleshoot the exact queries generated by an application.

I was wondering that how can we get this enabled in MySQL and monitor real time SQL queries in MySQL. After doing some RnD and searching over the internet, I finally got the option where we can enable queries logs.

Monitor SQL Queries in MySQL

The first thing we’ll need to do is turn on logging of queries in MySQL.

Please note that this should only be done in test or development environment because this log type is a performance killer. This really slows things down to log every single query to a file.

1.   Find and open your MySQL configuration file, my.cnf (for Linux) and my.ini (for Windows)
2.   Add below parameter as per OS type,
log = /var/log/mysql/mysql.log (for Linux) & log = <path>\mysql.log
4.   Restart the MySQL service
5.   Now we’re ready to start monitoring the queries as they come in
6.   Now run your application. You’ll see the database queries are getting logged in mysql.log file.

<<Click here to see all posts>>

If you found any of the information on this page helpful in anyway then please consider sharing this content with your favorite social network or by leaving your thoughts in the comment section. Thanks!

Leave a Reply

Your email address will not be published. Required fields are marked *

Prove You Are Human Time limit is exhausted. Please reload CAPTCHA.