Mysql top just like we have top command in Linux

08 / Oct / 2011 by Anuj Aneja 0 comments
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

Tag -

Linux MySql
FOUND THIS USEFUL? SHARE IT

Leave a comment -