Please whitelist cPanel in your adblocker so that you’re able to see our version release promotions, thanks!

The Community Forums

Interact with an entire community of cPanel & WHM users!

Check MySQL queries

Discussion in 'General Discussion' started by NixTree, Nov 25, 2011.

  1. NixTree

    NixTree Well-Known Member

    Joined:
    Aug 19, 2010
    Messages:
    407
    Likes Received:
    3
    Trophy Points:
    143
    Location:
    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.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  2. sehh

    sehh Well-Known Member

    Joined:
    Feb 11, 2006
    Messages:
    579
    Likes Received:
    5
    Trophy Points:
    168
    Location:
    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.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  3. cPanelTristan

    cPanelTristan Quality Assurance Analyst
    Staff Member

    Joined:
    Oct 2, 2010
    Messages:
    7,608
    Likes Received:
    32
    Trophy Points:
    238
    Location:
    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
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  4. NixTree

    NixTree Well-Known Member

    Joined:
    Aug 19, 2010
    Messages:
    407
    Likes Received:
    3
    Trophy Points:
    143
    Location:
    Gods Own Country
    cPanel Access Level:
    Root Administrator
    Twitter:
    Hello Tristan,

    Its "5.0.92".

    Thanks for your reply!

    Thank you,
    Nibin.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  5. cPanelTristan

    cPanelTristan Quality Assurance Analyst
    Staff Member

    Joined:
    Oct 2, 2010
    Messages:
    7,608
    Likes Received:
    32
    Trophy Points:
    238
    Location:
    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
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
Loading...

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice