{"id":4363,"date":"2011-10-08T14:14:14","date_gmt":"2011-10-08T08:44:14","guid":{"rendered":"http:\/\/www.tothenew.com\/blog\/?p=4363"},"modified":"2017-02-12T19:21:08","modified_gmt":"2017-02-12T13:51:08","slug":"mysql-top-just-like-we-have-top-command-in-linux","status":"publish","type":"post","link":"https:\/\/www.tothenew.com\/blog\/mysql-top-just-like-we-have-top-command-in-linux\/","title":{"rendered":"Mysql top just like we have top command in Linux"},"content":{"rendered":"<div>Once in my grails project i was facing the problem of freeze of server.When this happens tomcat becomes unresponsive.Later on by\u00a0analyzing\u00a0the 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.<\/div>\n<p>Show processlist;<\/p>\n<p>Which gives us the result as:<br \/>\nOutput:<br \/>\n+&#8212;&#8211;+&#8212;&#8212;+&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;+&#8212;&#8212;&#8212;+&#8212;&#8212;+&#8212;&#8212;-+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;+<\/p>\n<p>| Id \u00a0| User | Host \u00a0 \u00a0 \u00a0| db \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0| Command | Time | State | Info \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 |<\/p>\n<p>+&#8212;&#8211;+&#8212;&#8212;+&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;+&#8212;&#8212;&#8212;+&#8212;&#8212;+&#8212;&#8212;-+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;+<\/p>\n<p>| 242 | root | localhost | \u00a0 \u00a0 \u00a0test_db \u00a0 \u00a0| Query \u00a0 | \u00a0 \u00a00 | NULL \u00a0| show processlist |<\/p>\n<p>+&#8212;&#8211;+&#8212;&#8212;+&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;+&#8212;&#8212;&#8212;+&#8212;&#8212;+&#8212;&#8212;-+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;+<\/p>\n<p>The output shows how many connections are active and their properties.<br \/>\nBut for this you need to run the query again and again to analyse the connections information. For a better experience we can use mytop \u00a0which is very easy to install and just like the top in linux, simple steps need to be followed to make it work.<\/p>\n<p>Step 1:Install mytop using the following command.<\/p>\n<p>anuj@intelligrape:~$ sudo apt-get install mytop<br \/>\nStep 2:<br \/>\nAfter installation we need make a configuration file .mysqlconfig any where<br \/>\ne.g<br \/>\nanuj@intelligrape:~$ vim .mysqlconfig<br \/>\nuser=<\/p>\n<p>pass=<\/p>\n<p>host=localhost<\/p>\n<p>db=db_name<\/p>\n<p>delay=5<\/p>\n<p>port=330<\/p>\n<p>6socket=<\/p>\n<p>batchmode=0<\/p>\n<p>header=1<\/p>\n<p>color=1<\/p>\n<p>idle=1<\/p>\n<p>For more option you can refer to documentation of mytop .<br \/>\nStep 3:<br \/>\nNow just need run this command to see the mysqltop working.<br \/>\nanuj@intelligrape:~$ mytop ~\/.mysqlconfig<br \/>\noutput:<\/p>\n<p>Thats it ! Internally it runs the query &#8220;show processlist&#8221; and is very elegant for analysing mysql connections.<\/p>\n<p>This helps me! Hope this helps you guys!<br \/>\nAnuj Aneja<\/p>\n<p>Intelligrape Software<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Once in my grails project i was facing the problem of freeze of server.When this happens tomcat becomes unresponsive.Later on by\u00a0analyzing\u00a0the 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; [&hellip;]<\/p>\n","protected":false},"author":27,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"iawp_total_views":11},"categories":[7],"tags":[260,76],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/4363"}],"collection":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/users\/27"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/comments?post=4363"}],"version-history":[{"count":0,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/4363\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/media?parent=4363"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/categories?post=4363"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/tags?post=4363"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}