The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Check MySQL queries

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

  1. NixTree

    NixTree Well-Known Member

    Joined:
    Aug 19, 2010
    Messages:
    386
    Likes Received:
    1
    Trophy Points:
    18
    Location:
    Gods Own Country
    cPanel Access Level:
    Root Administrator
    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.
     
  2. sehh

    sehh Well-Known Member

    Joined:
    Feb 11, 2006
    Messages:
    579
    Likes Received:
    5
    Trophy Points:
    18
    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.
     
  3. cPanelTristan

    cPanelTristan Quality Assurance Analyst
    Staff Member

    Joined:
    Oct 2, 2010
    Messages:
    7,623
    Likes Received:
    21
    Trophy Points:
    38
    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
     
  4. NixTree

    NixTree Well-Known Member

    Joined:
    Aug 19, 2010
    Messages:
    386
    Likes Received:
    1
    Trophy Points:
    18
    Location:
    Gods Own Country
    cPanel Access Level:
    Root Administrator
    Hello Tristan,

    Its "5.0.92".

    Thanks for your reply!

    Thank you,
    Nibin.
     
  5. cPanelTristan

    cPanelTristan Quality Assurance Analyst
    Staff Member

    Joined:
    Oct 2, 2010
    Messages:
    7,623
    Likes Received:
    21
    Trophy Points:
    38
    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
     
Loading...

Share This Page