How to Monitor SQL queries
by David Pham • October 2, 2014 • Blog
In PHP web development what relate to database, I usually want to check my SQL detail. But not all of time, I can debug line by line or print out the SQL query to check. Instead of showing SQL queries, I will make it show everything in mysql log file with detail of SQL to check. Here is the easiest way to monitor SQL queries in Linux (you can do the same in Windows or Mac).
Visit the mysql configuration file:
1 |
/etc/mysql/my.cnf |
Find and uncomment this line
1 2 3 4 |
# Both location gets rotated by the cronjob. # Be aware that this log type is a performance killer. log = /var/log/mysql/mysql.log |
Now restart mysql server
1 |
sudo /etc/init.d/mysql restart |
Now we’re ready to start monitoring the queries as they come in. Open up a new terminal and run this command to scroll the log file, adjusting the path if necessary.
1 |
tail -f /var/log/mysql/mysql.log |