{"id":334,"date":"2013-05-15T13:39:01","date_gmt":"2013-05-15T13:39:01","guid":{"rendered":"http:\/\/www.scmgalaxy.com\/tutorials\/2013\/05\/15\/mysql-basic-troubleshooting-guide\/"},"modified":"2017-12-25T01:57:45","modified_gmt":"2017-12-25T01:57:45","slug":"mysql-basic-troubleshooting-guide","status":"publish","type":"post","link":"https:\/\/www.devopsschool.com\/blog\/mysql-basic-troubleshooting-guide\/","title":{"rendered":"MySQL Basic Troubleshooting Guide | MySQL common Issues"},"content":{"rendered":"<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-3783 aligncenter\" src=\"http:\/\/www.scmgalaxy.com\/tutorials\/wp-content\/uploads\/2013\/05\/mysql-troubleshooting.png\" alt=\"mysql-troubleshooting\" width=\"600\" height=\"400\" srcset=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2013\/05\/mysql-troubleshooting.png 600w, https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2013\/05\/mysql-troubleshooting-300x200.png 300w\" sizes=\"auto, (max-width: 600px) 100vw, 600px\" \/><\/p>\n<p>PLEASE NOTE: I am currently reviewing this Article.<\/p>\n<p><strong>How to check the mysql file location:<\/strong><br \/>\n&gt; which mysql<br \/>\n&gt; locate mysql<\/p>\n<p><strong>Check mysqld process is started or not?<\/strong><br \/>\n&gt; service mysqld status<br \/>\n&gt; \u201cmysqld is stopped\u201d \u2013 Means mysqld is not running<br \/>\n&gt; \u201cmysqld: unrecognized service\u201d \u2013 Means mysqld is not set in service. This can be register using chkconfig under \/etc\/init.d.<br \/>\n&gt; ps -eaf | grep mysqld<\/p>\n<p><strong>To check if port 3306 is bind with mysqld or another program.<\/strong><br \/>\n&gt; lsof -i TCP:3306<br \/>\n&gt; netstat -lp | grep 3306<br \/>\n&gt; netstat -tap | grep mysql<br \/>\n&gt; ps -aux | grep mysql<br \/>\n&gt; netstat -a -t &#8211; to show only tcp ports<\/p>\n<p>Note: &#8211; if you could not found 3306 is listening with mysqld, then it must not be running or running with another ports. To find this, refer my.cnf and pid-file<\/p>\n<p><strong>How to Stop mysqld?<\/strong><br \/>\n&gt; \/etc\/init.d\/mysqld stop<br \/>\n&gt; kill &lt;pid&gt;<br \/>\n&gt; \/sbin\/service mysqld start\/stop\/restart<\/p>\n<p>If you have problems starting the server, here are some things to try:<\/p>\n<p><strong>Check the error log to see why the server does not start.<\/strong><br \/>\nThe Location of error log file can be found in my.cnf or my.ini(windows). please refer below to know more about my.cnf file. The log file can be specified also in mysqld service resided<br \/>\nunder \/etc\/init.d\/<\/p>\n<p><strong>Make sure that the server knows where to find the data directory.<\/strong><br \/>\nMake sure my.cnf file is set with &#8220;datadir&#8221; and its required ownership and permission. Make sure that the server can access the data directory. The ownership and permissions of the data directory and its contents must be set such that the server can read and modify them.<\/p>\n<p><strong>Verify that the network interfaces the server wants to use are available. If the server starts but you cannot connect to it, you should make sure that you have an entry in \/etc\/hosts that<br \/>\nlooks like this:<\/strong><br \/>\n127.0.0.1 localhost<\/p>\n<p><strong>If mysqld is running, To find all the variable set using <\/strong><br \/>\n&gt; mysqladmin -h hostname -p variables<\/p>\n<p><strong>Issues 1:<\/strong><br \/>\nCan&#8217;t start server: Bind on TCP\/IP port: Address already in use<br \/>\nCan&#8217;t start server: Bind on unix socket&#8230;<br \/>\n<strong>Solution:<\/strong><br \/>\nUse ps to determine whether you have another mysqld server running. If so, shut down the server before starting mysqld again.<\/p>\n<p><strong>Issues 2:<\/strong><br \/>\nmysqld will not start<br \/>\nCan&#8217;t start server: Bind on TCP\/IP port: Address already in use<br \/>\nDo you already have another mysqld server running on port: 3306 ?<br \/>\n<strong>Solution:<\/strong><br \/>\nThis may be due to 3306 port is being used or Disk Space issues. You can look up on the log file.<\/p>\n<p><strong>Recovering a crashed MySQL server if the system itself or just the MySQL daemon corrupted table files<\/strong><\/p>\n<p>You\u2019ll see this when checking the \/var\/log\/syslog, as the MySQL daemon checks tables during its startup.<\/p>\n<p>Apr 17 13:54:44 live1 mysqld[2613]: 090417 13:54:44 [ERROR]<br \/>\n\/usr\/sbin\/mysqld: Table &#8216;.\/database1\/table1&#8217; is marked as<br \/>\ncrashed and should be repaired<\/p>\n<p>In this situation, Database and tables need to be repaired.<\/p>\n<p>&gt; mysql -u root -p<br \/>\nmysql&gt; REPAIR TABLE database1.table1;<\/p>\n<p>This works, but there is a better way: First, using OPTIMIZE in combination with REPAIR is suggested and there is a command line tool only for REPAIR jobs. Consider this call:<br \/>\n&gt; mysqlcheck -u username -p -o &#8211;auto-repair -v &#8211;optimize database_name<\/p>\n<p>Using \u201cmysqlcheck\u201d is, that it can also be run against all databases in one run<br \/>\n&gt; mysqlcheck -u root -p &#8211;auto-repair &#8211;check &#8211;optimize &#8211;all-databases<\/p>\n<p>Recreating databases and tables the right way<br \/>\nmysql&gt; show create database database1;<\/p>\n<p><strong>How to find location of my.cnf (or my.ini on Windows)?<\/strong><\/p>\n<p>Default options are read from the following files in the given order:<br \/>\n\/etc\/my.cnf<br \/>\n\/etc\/mysql\/my.cnf<br \/>\n\/usr\/etc\/my.cnf<br \/>\n~\/.my.cnf<\/p>\n<p>Or, on Windows:<br \/>\nDefault options are read from the following files in the given order:<br \/>\nC:\\Windows\\my.ini<br \/>\nC:\\Windows\\my.cnf<br \/>\nC:\\my.ini<br \/>\nC:\\my.cnf<br \/>\nC:\\Program Files\\MySQL\\MySQL Server 5.5\\my.ini<br \/>\nC:\\Program Files\\MySQL\\MySQL Server 5.5\\my.cnf<\/p>\n<p><strong>This command also help you in linux to find my.conf file location&#8230;<\/strong><br \/>\n&gt; strace mysql &#8220;;&#8221; 2&gt;&amp;1 | grep cnf<\/p>\n<p><strong>Another Option to use following commands&#8230;<\/strong><br \/>\n&gt; whereis my.cnf<br \/>\n&gt; locate my.cnf<br \/>\n&gt; find &#8211; -name my.cnf<\/p>\n<p><strong>my.cnf will contain following&#8230;<\/strong><br \/>\ndatadir &#8211; The path to the MySQL data directory.<br \/>\ntmpdir<br \/>\ndefault-character-set<br \/>\ndefault-storage-engine<br \/>\ninnodb_data_home_dir<br \/>\nlog-error- The location of log file.<br \/>\npid-file &#8211; The path name of the file in which the server should write its process ID.<\/p>\n<p><strong>MySQL Performance Troubleshooting<\/strong><br \/>\nThere are three main utilities I\u2019ll run to in a situation like this:<\/p>\n<p>top<br \/>\nFirst I\u2019m going to use top to see if anything is hogging CPU on the machine. If there are non-mysql processes using a substantial percentage of the CPU cores, I\u2019m going to want to havea look at what that is and see about limiting its use or moving it a dedicated server. If I see mysqld using up a lot of CPU, I know it\u2019s working hard and will have to drill into what\u2019shappening inside of MySQL (maybe some poorly written queries). If nothing is apparently chewing up the CPU time, I know that the problem is likely elsewhere.<\/p>\n<p>vmstat 5<br \/>\nI generally run this for at least two or three minutes to get a sense of what the CPU and memory use are like. I\u2019m also watching to see how much time the CPU is stalled waiting for I\/Orequests. Doing this for several minutes will make the occasional spikes really stand out and also allow for more time to catch those cron jobs that fire up every few minutes.<\/p>\n<p>iostat -x 5 | grep sdb<br \/>\nI\u2019m going to run it with a short interval (5 or 10 seconds) and do so for several minutes. I\u2019ll likely filter the output so that I only see the output for the most active disk or array (the onewhere all of MySQL\u2019s data lives).<\/p>\n<p>slow queries<br \/>\nTo find out about slow queries I\u2019m going hope that the slow query log is enabled and the server has a sane long_query_time. But even the default of 10 seconds is helpful in truly badsituations.<\/p>\n<p><strong>MySQL\u2019s error log<\/strong><br \/>\nI\u2019ll also want to glance through MySQL\u2019s error log to make sure nothing bad-looking has started to appear. To Find a error log file location, refer my.cnf file &#8220;log-error&#8221;.<\/p>\n<p><strong>Network issues<\/strong><br \/>\ntelnet your_host_name tcp_ip_port_number.<\/p>\n<p><strong>mysqladmin : <\/strong><br \/>\nmysqladmin is a client for performing administrative operations. You can use it to check the server&#8217;s configuration and current status, to create and drop databases, and more.<\/p>\n<p>mysqladmin -h hostname -p &lt;command_as_follows&gt;<\/p>\n<p>&#8211;help, -? &#8211; Display a help message and exit.<br \/>\nrefresh &#8211; Flush all tables and close and open log files.<br \/>\nvariables &#8211; Display the server system variables and their values.<br \/>\nflush-logs &#8211; Flush all logs.<br \/>\nflush-privileges &#8211; Reload the grant tables (same as reload).<br \/>\nflush-status &#8211; Clear status variables.<br \/>\npassword new-password &#8211; Set a new password. This changes the password to new-password for the account that you use with mysqladmin for connecting to the server.<br \/>\nping &#8211; Check whether the server is available<br \/>\nprocesslist &#8211; Show a list of active server threads.<br \/>\nshutdown &#8211; Stop the server.<br \/>\nstatus &#8211; Display a short server status message.<br \/>\nUptime &#8211; The number of seconds the MySQL server has been running.<br \/>\nSlow queries &#8211; The number of queries that have taken more than long_query_time seconds<br \/>\nOpen tables &#8211; The number of tables that currently are open.<\/p>\n<p><strong>Reference<\/strong><br \/>\n<a href=\"http:\/\/dev.mysql.com\/doc\/refman\/5.5\/en\/mysqladmin.html\" target=\"_blank\" rel=\"noopener\">http:\/\/dev.mysql.com\/doc\/refman\/5.5\/en\/mysqladmin.html<\/a><br \/>\n<a href=\"http:\/\/dev.mysql.com\/doc\/refman\/5.1\/en\/slow-query-log.html\" target=\"_blank\" rel=\"noopener\">http:\/\/dev.mysql.com\/doc\/refman\/5.1\/en\/slow-query-log.html<\/a><br \/>\n<a href=\"http:\/\/www.linux-mag.com\/id\/7473\/\" target=\"_blank\" rel=\"noopener\">http:\/\/www.linux-mag.com\/id\/7473\/<\/a><br \/>\n<a href=\"http:\/\/dev.mysql.com\/doc\/refman\/5.1\/en\/starting-server.html\" target=\"_blank\" rel=\"noopener\">http:\/\/dev.mysql.com\/doc\/refman\/5.1\/en\/starting-server.html<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>PLEASE NOTE: I am currently reviewing this Article. How to check the mysql file location: &gt; which mysql &gt; locate mysql Check mysqld process is started or not? &gt; service mysqld status &gt; \u201cmysqld is stopped\u201d \u2013 Means mysqld is not running &gt; \u201cmysqld: unrecognized service\u201d \u2013 Means mysqld is not set in service. This&#8230;<\/p>\n","protected":false},"author":1,"featured_media":3783,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_kad_post_transparent":"","_kad_post_title":"","_kad_post_layout":"","_kad_post_sidebar_id":"","_kad_post_content_style":"","_kad_post_vertical_padding":"","_kad_post_feature":"","_kad_post_feature_position":"","_kad_post_header":false,"_kad_post_footer":false,"_kad_post_classname":"","_joinchat":[],"footnotes":""},"categories":[49],"tags":[2380,2396,545,255,493,2394,2395,2393,2387,2398,2390,2391,2388,2389,2397,2392,293],"class_list":["post-334","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-general","tag-buildforge-server","tag-common-problems-in-mysql","tag-how","tag-issues","tag-mysql","tag-mysql-basic-issues","tag-mysql-basic-problems","tag-mysql-basic-troubleshooting","tag-mysql-common-issues","tag-mysql-guide","tag-mysql-issues","tag-mysql-problems","tag-mysql-troubleshooting","tag-mysql-troubleshooting-guide","tag-mysql-tutorial","tag-troubleshoot-mysql","tag-troubleshooting"],"_links":{"self":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/334","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/comments?post=334"}],"version-history":[{"count":2,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/334\/revisions"}],"predecessor-version":[{"id":3782,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/334\/revisions\/3782"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/media\/3783"}],"wp:attachment":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/media?parent=334"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/categories?post=334"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/tags?post=334"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}