11

i have a busy web server with LAMP installed, and i was wondering, is there any way to count how many queries per second (mysql) are executed in the server ?

Thank you.

Nikos
  • 121
  • 1
  • 2
  • 5

6 Answers6

11
SELECT s1.variable_value / s2.variable_value
FROM information_schema.global_status s1, information_schema.global_status s2
WHERE s1.variable_name='queries'
AND s2.variable_name ='uptime';
n00b
  • 131
  • 1
  • 3
8

Try Jeremy Zawodny's excellent utility mytop.

If you have the Perl module Time::HiRes installed, mytop will automatically use it to generate high-resoution query per second information.

Bill Karwin
  • 538,548
  • 86
  • 673
  • 828
5

There's useful information to be mined from the SHOW GLOBAL STATUS; command, including the number of queries executed (if your MySQL is 5.0.76 or later).

See http://dev.mysql.com/doc/refman/5.0/en/server-status-variables.html

Dave W. Smith
  • 24,318
  • 4
  • 40
  • 46
  • what all the questions included as part of this queries...? – Uday Aug 16 '12 at 00:20
  • I am serching for how mysql calculates this questions values or queries values. I am doing the sum of COM_SELECT, COM_UPDATE, COM_SET_OPTION, COM_UPDATE, COM_DELETE and few more but not getting the exact match between these two. – Uday Aug 16 '12 at 00:22
  • 2
    The diff between `Questions` and `Queries` may involve Stored Routines. – Rick James Mar 19 '18 at 14:00
5

You can use:

 mysqladmin -u root -p  status

which will return output like:

Uptime: 17134  Threads: 2  Questions: 1245  Slow queries: 0  Opens: 49  Flush tables: 1  Open tables: 42  Queries per second avg: 0.072

Here queries per second is: 0.072, which is questions/uptime.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Prashant Prabhakar Singh
  • 1,120
  • 4
  • 15
  • 33
2

When you use the "STATUS" command (not SHOW STATUS), MySQL will calculate the queries per second since server start for you.

Tested with MySQL 5.1.63.

Gene Vincent
  • 5,237
  • 9
  • 50
  • 86
0

We can have a small script for this. It will be some thing like the below.

    declare -i a
    declare -i b
    declare -i c
    a=`mysql -uroot -pxxxxx -e "show status like 'Queries'" | 
    tail -1 | awk '{print    $2}'`
    echo "$a"
    sleep 1
    b=`mysql -uroot -pxxxxx -e "show status like 'Queries'" | 
    tail -1 | awk '{print                 $2}'`
    echo "$b"
    c=$b-$a
    echo "Number of Queries per second is: $c"
Uday
  • 1,480
  • 4
  • 27
  • 44