InfoHeap
Tech
Navigation
  • Home
  • Tutorials
    • CSS tutorials & examples
    • CSS properties
    • Javascript cookbook
    • Linux/Unix Command Line
    • Mac
    • PHP
      • PHP functions online
      • PHP regex
    • WordPress
  • Online Tools
    • Text utilities
    • Online Lint Tools
search

Mysql tutorials

  • Enable query log without restarting mysql on Linux
  • How to find mysql query rate on Linux
  • Mysql - display row count and size of tables
  • Mysql - get size of all databases
  • Mysql - get total queries since beginning
  • Mysql - how to copy a table
  • Mysql - how to enable query log
  • Mysql 5.7 root password after installation
  • Mysql difference between CURDATE() and NOW()
  • Mysql find current timezone offset
  • Mysql find slave lag
  • Mysql how to dump schema of all databases
  • Mysql multi column Index
  • Wordpress Mysql Queries
  • mysql - how to enable query logs
  • mysql find recently created-tables
 
  • Home
  • > Tutorials
  • > Mysql

How to find mysql query rate on Linux

By admin on Nov 15, 2015

Sometimes we want to know the current queries rate being sent to mysql server. This can be useful to get some idea on query load on mysql server. We can also use similar approach to find current rows read rate, etc. which can give an idea of current data being transferred from mysql server. Here are steps to find query rate on Ubuntu Linux Command line. We’ll use mysql “SHOW STATUS” command for the purpose of this article.

mysql-show-status-like-queries

Find total queries executed since start of mysql

First we’ll use mysql status command to get the total query count since mysql start. Run the following command to find total queries executed so far:

$ mysql -u root  -e 'SHOW STATUS like "Queries"'
+---------------+----------+
| Variable_name | Value    |
+---------------+----------+
| Queries       | 47083727 |
+---------------+----------+
Note that here we are assuming you are running these queries on the mysql instance and your root password is empty. In case you have a root password, you can use --password=value. To get just the count value run the following:
$ mysql -u root --skip-column-names -e 'SHOW STATUS like "Queries"' | awk '{print $2}'
47083727

Calculate mysql query rate

Two find query rate, we’ll get the query count value at two different points of time. Save the following script to a file mysql_query_rate.sh:

#!/bin/bash
C1=$(mysql -u root --skip-column-names -e 'SHOW STATUS like "Queries"' | awk '{print $2}')
sleep 60
C2=$(mysql -u root --skip-column-names -e 'SHOW STATUS like "Queries"' | awk '{print $2}')
R=$(echo "($C2 - $C1)/60" | bc -l)
echo $R

Run the following code to get the query rate:

$ chmod a+x mysql_query_rate.sh
$ ./mysql_query_rate.sh
8.6666666666666666666

Other mysql stats

Note that you can also calculate few other types of query rate using a similar approach. Some of the stats you can consider are:

  1. Innodb_rows_deleted
  2. Innodb_rows_inserted
  3. Innodb_rows_read
  4. Innodb_rows_updated
  5. Slow_queries

Suggested posts:

  1. How to kill unresponsive ssh session using escape sequence
  2. Chrome – copy any request as cURL including headers
  3. WordPress – get posts/pages with missing meta key
  4. prevent wordpress xmlrpc.php attack
  5. Git – rename local branch
  6. CSS – round toggle switch using checkbox and label
  7. WordPress themes for beginners worth considering
  8. Curl – follow redirects
Share this article: share on facebook share on linkedin tweet this submit to reddit
Posted in Tutorials | Tagged Bash shell scripting, Linux/Unix Command Line, Mysql, Tutorials
  • Browse content
  • Article Topics
  • Article archives
  • Contact Us
Popular Topics: Android Development | AngularJS | Apache | AWS and EC2 | Bash shell scripting | Chrome developer tools | Company results | CSS | CSS cookbook | CSS properties | CSS Pseudo Classes | CSS selectors | CSS3 | CSS3 flexbox | Devops | Git | HTML | HTML5 | Java | Javascript | Javascript cookbook | Javascript DOM | jQuery | Kubernetes | Linux | Linux/Unix Command Line | Mac | Mac Command Line | Mysql | Networking | Node.js | Online Tools | PHP | PHP cookbook | PHP Regex | Python | Python array | Python cookbook | SEO | Site Performance | SSH | Ubuntu Linux | Web Development | Webmaster | Wordpress | Wordpress customization | Wordpress How To | Wordpress Mysql Queries | InfoHeap Money

Copyright © 2025 InfoHeap.

Powered by WordPress