Mysql top just like we have top command in Linux « Intelligrape Groovy & Grails Blogs

Mysql top just like we have top command in Linux

Posted by
Once in my grails project i was facing the problem of freeze of server.When this happens tomcat becomes unresponsive.Later on by analyzing the thread dump we found that this problem might be due to the database and tomcat communication. So as to analyse how many connection are active at mysql end we found a query.

Show processlist;

Which gives us the result as:
Output:
+—–+——+———–+———————+———+——+——-+——————+

| Id  | User | Host      | db                      | Command | Time | State | Info             |

+—–+——+———–+———————+———+——+——-+——————+

| 242 | root | localhost |      test_db    | Query   |    0 | NULL  | show processlist |

+—–+——+———–+———————+———+——+——-+——————+

The output shows how many connections are active and their properties.
But for this you need to run the query again and again to analyse the connections information. For a better experience we can use mytop  which is very easy to install and just like the top in linux, simple steps need to be followed to make it work.

Step 1:Install mytop using the following command.

anuj@intelligrape:~$ sudo apt-get install mytop
Step 2:
After installation we need make a configuration file .mysqlconfig any where
e.g
anuj@intelligrape:~$ vim .mysqlconfig
user=

pass=

host=localhost

db=db_name

delay=5

port=330

6socket=

batchmode=0

header=1

color=1

idle=1

For more option you can refer to documentation of mytop .
Step 3:
Now just need run this command to see the mysqltop working.
anuj@intelligrape:~$ mytop ~/.mysqlconfig
output:

Thats it ! Internally it runs the query “show processlist” and is very elegant for analysing mysql connections.

This helps me! Hope this helps you guys!
Anuj Aneja

Intelligrape Software

Tags: ,
This entry was posted on October 8th, 2011 at 2:14 pm and is filed under Grails . You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

One Response to “Mysql top just like we have top command in Linux”

  1. we have says:

    we have…

    [...]Mysql top just like we have top command in Linux « Intelligrape Groovy & Grails Blogs[...]…

Leave a Reply