{"id":26,"date":"2006-09-18T14:15:13","date_gmt":"2006-09-18T14:15:13","guid":{"rendered":"http:\/\/ramblingsofasysadmin.com\/blog\/?p=26"},"modified":"2006-09-18T14:15:13","modified_gmt":"2006-09-18T14:15:13","slug":"showing-and-understanding-mysql-processes-in-detail","status":"publish","type":"post","link":"https:\/\/ramblingsofasysadmin.com\/?p=26","title":{"rendered":"showing and understanding mysql processes in detail."},"content":{"rendered":"<p>i&#8217;ve learned a little trick on how to determine how your mysql server is running and where to pinpoint problems in the event of a heavy load.  this is useful in determining how you might want to proceed in terms of mysql optimization.<br \/>\n<font face=\"courier\"># mysql -u [adminuser] -p<br \/>\nmysql> show processlist;<\/font><br \/>\ngranted, on a server with heavy volume, you might see hundreds of rows and it will scroll off the screen.  here are the key elements to the processlist table: Id, User, Host, db, Command, Time, State, Info, where:<br \/>\n<b>Id<\/b> is the connection identifier<br \/>\n<b>User<\/b> is the mysql user who issued the statement<br \/>\n<b>Host<\/b> is the hostname of the client issuing the statement.  this will be localhost in almost all cases unless you are executing commands on a remote server.<br \/>\n<b>db<\/b> is the database being used for the particular mysql statement or query.<br \/>\n<b>Command<\/b> can be one of many different commands issued in the particular query.  the most common occurrence on a webserver is &#8220;Sleep,&#8221; which means that the particular database connection is waiting for new directions or a new statement.<br \/>\n<b>Time<\/b> is the delay between the original time of execution of the statement and the time the processlist is viewed<br \/>\n<b>State<\/b> is an action, event, or state of the specific mysql command and can be one of hundreds of different values.<br \/>\n<b>Info<\/b> will show the actual statement being run in that instance<br \/>\nanother useful command is:<br \/>\n<font face=\"courier\">mysql> show full processlist;<\/font><br \/>\nwhich is equivalent to:<br \/>\n<font face=\"courier\">mysqladmin -u [adminuser] -p processlist;<\/font><br \/>\nthis shows my specific query as:<br \/>\n<font face=\"courier\">| 4342233 | adminusername   | localhost | NULL               | Query   |    0 | NULL  | show full processlist |<\/font><br \/>\n<\/font><br \/>\nor you can display each field in a row format (vertical format), like so, simply by appending <font face=\"courier\">\\G<\/font> to the end of the query:<br \/>\n<font face=\"courier\">mysql> show full processlist\\G<\/font><br \/>\nthis list is very likely preferable in the event that your data scrolls off the screen and you want to find out the specific field name of a value in your database.<br \/>\n<font face=\"courier\">******** 55. row ********<br \/>\nId: 4342233<br \/>\nUser: adminusername<br \/>\nHost: localhost<br \/>\ndb: NULL<br \/>\nCommand: Query<br \/>\nTime: 0<br \/>\nState: NULL<br \/>\nInfo: show full processlist<br \/>\n<\/font><br \/>\nyou can also check how many mysql queries a user has open by running the following command:<br \/>\n<font face=\"courier\">mysqladmin -u [adminuser] -p pr | awk -F\\| {&#8216;print $3&#8217;} | sort -nk1 | awk -F_ {&#8216;print $1&#8217;} |uniq -c |sort<\/font><br \/>\nto see which database has the most active queries, run the following:<br \/>\n<font face=\"courier\">mysqladmin -u [adminuser] -p pr | awk -F\\| {&#8216;print $3&#8217;} | sort -nk1 |uniq -c |sort<\/font><br \/>\noh, and since it&#8217;s useful&#8230; here&#8217;s a recommend <font face=\"courier\">\/etc\/my.cnf<\/font>:<br \/>\n<font face=\"courier\"><br \/>\n[mysqld]<br \/>\ndatadir=\/var\/lib\/mysql<br \/>\nskip-locking<br \/>\nskip-innodb<br \/>\nsafe-show-database<br \/>\nquery_cache_limit=1M<br \/>\nquery_cache_size=64M<br \/>\nquery_cache_type=1<br \/>\nmax_user_connections=100<br \/>\nmax_connections=350<br \/>\ninteractive_timeout=10<br \/>\nwait_timeout=20<br \/>\nconnect_timeout=20<br \/>\nthread_cache_size=128<br \/>\nkey_buffer=64M<br \/>\njoin_buffer=1M<br \/>\nmax_connect_errors=20<br \/>\nmax_allowed_packet=16M<br \/>\ntable_cache=1024<br \/>\nrecord_buffer=1M<br \/>\nsort_buffer_size=2M<br \/>\nread_buffer_size=2M<br \/>\nread_rnd_buffer_size=2M<br \/>\nthread_concurrency=4<br \/>\nmyisam_sort_buffer_size=64M<br \/>\nserver-id=1<br \/>\nlong_query_time=2<br \/>\nslave_net_timeout = 50<br \/>\ndelayed_insert_timeout = 50<br \/>\n[mysql.server]<br \/>\nuser=mysql<br \/>\nbasedir=\/var\/lib<br \/>\n[safe_mysqld]<br \/>\nerr-log=\/var\/log\/mysqld.log<br \/>\npid-file=\/var\/lib\/mysql\/mysql.pid<br \/>\nopen_files_limit=8192<br \/>\n[mysqldump]<br \/>\nquick<br \/>\nmax_allowed_packet=16M<br \/>\n[mysql]<br \/>\nno-auto-rehash<br \/>\n[isamchk]<br \/>\nkey_buffer=64M<br \/>\nsort_buffer=64M<br \/>\nread_buffer=16M<br \/>\nwrite_buffer=16M<br \/>\n[myisamchk]<br \/>\nkey_buffer=64M<br \/>\nsort_buffer=64M<br \/>\nread_buffer=16M<br \/>\nwrite_buffer=16M<br \/>\n[mysqlhotcopy]<br \/>\ninteractive-timeout<br \/>\n<\/font><br \/>\nanother fine tuning would include the following and is good for machines with plesk:<br \/>\n<font face=\"courier\"><br \/>\nskip-locking<br \/>\nkey_buffer = 128M<br \/>\nmax_allowed_packet = 1M<br \/>\ntable_cache = 512<br \/>\nsort_buffer_size = 2M<br \/>\nread_buffer_size = 2M<br \/>\nread_rnd_buffer_size = 8M<br \/>\nmyisam_sort_buffer_size = 64M<br \/>\nthread_cache_size = 8<br \/>\nquery_cache_size = 64M<br \/>\nthread_concurrency = 8<br \/>\n<\/font><br \/>\nthe above will help you optimize your mysql database as well, but the configuration isn&#8217;t for everyone.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>i&#8217;ve learned a little trick on how to determine how your mysql server is running and where to pinpoint problems in the event of a heavy load. this is useful in determining how you might want to proceed in terms of mysql optimization. # mysql -u [adminuser] -p mysql> show processlist; granted, on a server with heavy volume, you might see hundreds of rows and it will scroll off the screen. here are the key <span class=\"ellipsis\">&hellip;<\/span> <span class=\"more-link-wrap\"><a href=\"https:\/\/ramblingsofasysadmin.com\/?p=26\" class=\"more-link\"><span>Read More &rarr;<\/span><\/a><\/span><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[],"class_list":["post-26","post","type-post","status-publish","format-standard","hentry","category-tutorials"],"_links":{"self":[{"href":"https:\/\/ramblingsofasysadmin.com\/index.php?rest_route=\/wp\/v2\/posts\/26","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ramblingsofasysadmin.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ramblingsofasysadmin.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ramblingsofasysadmin.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ramblingsofasysadmin.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=26"}],"version-history":[{"count":0,"href":"https:\/\/ramblingsofasysadmin.com\/index.php?rest_route=\/wp\/v2\/posts\/26\/revisions"}],"wp:attachment":[{"href":"https:\/\/ramblingsofasysadmin.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=26"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ramblingsofasysadmin.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=26"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ramblingsofasysadmin.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=26"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}