NixTree

Well-Known Member
Aug 19, 2010
413
5
143
Gods Own Country
cPanel Access Level
Root Administrator
Twitter
Hello,

Does anyone know, how to count the total number of sql queries generated when a webpage loads ( for eg: say a WordPress website )?

Thank you,
Nibin.
 

sehh

Well-Known Member
Feb 11, 2006
579
6
168
Europe
If the application calls a database library or class/object, then you modify the query function that performs the actual query to print/save the query string in a file or send it to syslog. That way you can see every single query.

This is easy in wordpress because it uses a single sql object to perform all queries.
 

cPanelTristan

Quality Assurance Analyst
Staff member
Oct 2, 2010
7,607
42
348
somewhere over the rainbow
cPanel Access Level
Root Administrator
You could simply turn on the MySQL general log in /etc/my.cnf location so that you get a log file to check how many queries loading a specific page or doing a specific action will write to the general log. If you let us know which MySQL version you are using, I can provide details on how to add the general log to the server. Here is how you would grab your MySQL version to provide to us:

Code:
mysql_config --version
 

cPanelTristan

Quality Assurance Analyst
Staff member
Oct 2, 2010
7,607
42
348
somewhere over the rainbow
cPanel Access Level
Root Administrator
Hello Nibin,

Please place the following into your /etc/my.cnf file:

Code:
log=/var/lib/mysql/general.log
Save the file, then create this file with the right ownership and permissions:

Code:
cd /var/lib/mysql
touch general.log
chown mysql:mysql general.log
chmod 660 general.log
At that point, restart MySQL:

Code:
/etc/init.d/mysql restart
You should be able to tail the log to see queries going to it now:

Code:
tail -fn0 /var/lib/mysql/general.log