{"id":2114,"date":"2022-08-30T15:22:10","date_gmt":"2022-08-30T15:22:10","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/01\/02\/cant-connect-to-local-mysql-server-through-socket-var-run-mysqld-mysqld-sock-2-collection-of-common-programming-errors\/"},"modified":"2022-08-30T15:22:10","modified_gmt":"2022-08-30T15:22:10","slug":"cant-connect-to-local-mysql-server-through-socket-var-run-mysqld-mysqld-sock-2-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2022\/08\/30\/cant-connect-to-local-mysql-server-through-socket-var-run-mysqld-mysqld-sock-2-collection-of-common-programming-errors\/","title":{"rendered":"Can&#39;t connect to local MySQL server through socket &#39;\/var\/run\/mysqld\/mysqld.sock&#39; (2)-Collection of common programming errors"},"content":{"rendered":"<p>I have mailserver configure using dovecot+postfix+mysql and it was runnig fine in the server(Ubuntu Server). But during last week it stopped working correctly. It doesn&#8217;t send email. When I try to <code>telnet localhost smtp<\/code> I&#8217;m connecting successfully but when I do <code>mail from:<\/code> and hit Enter it hangs on, nothing happen.<\/p>\n<p>Having reviewed <code>\/var\/log\/mail.log<\/code> file I&#8217;ve found out that probably(99%) the problem is on postfix when it is trying to connect to MySQL server. If you see the log file given below you can see that it says <code>Can't connect to local MySQL server through socket '\/var\/run\/mysqld\/mysqld.sock' (2)<\/code>.<\/p>\n<pre><code>Nov 14 21:54:36 ns1 dovecot: dovecot: Killed with signal 15 (by pid=7731 uid=0 code=kill)\nNov 14 21:54:36 ns1 dovecot: Dovecot v1.2.9 starting up (core dumps disabled)\nNov 14 21:54:36 ns1 dovecot: auth-worker(default): mysql: Connected to localhost (mailserver)\nNov 14 21:54:44 ns1 postfix\/postfix-script[7753]: refreshing the Postfix mail system\nNov 14 21:54:44 ns1 postfix\/master[1670]: reload -- version 2.7.0, configuration \/etc\/postfix\nNov 14 21:54:52 ns1 postfix\/trivial-rewrite[7759]: warning: connect to mysql server localhost: Can't connect to local MySQL server through socket '\/var\/run\/mysqld\/mysqld.sock' (2)\nNov 14 21:54:52 ns1 postfix\/trivial-rewrite[7759]: fatal: mysql:\/etc\/postfix\/mysql-virtual-alias-maps.cf(0,lock|fold_fix): table lookup problem\nNov 14 21:54:53 ns1 postfix\/master[1670]: warning: process \/usr\/lib\/postfix\/trivial-rewrite pid 7759 exit status 1\nNov 14 21:54:53 ns1 postfix\/cleanup[7397]: warning: problem talking to service rewrite: Connection reset by peer\nNov 14 21:54:53 ns1 postfix\/master[1670]: warning: \/usr\/lib\/postfix\/trivial-rewrite: bad command startup -- throttling\nNov 14 21:54:53 ns1 postfix\/smtpd[7071]: warning: problem talking to service rewrite: Success\n<\/code><\/pre>\n<p>I tried <code>netstat -ln | grep mysql<\/code> and it returns<\/p>\n<p><code>unix 2 [ ACC ] STREAM LISTENING 5817 \/var\/run\/mysqld\/mysqld.sock<\/code>.<\/p>\n<p>The content of <code>\/etc\/postfix\/mysql-virtual-alias-maps.cf<\/code> file is here:<\/p>\n<pre><code>user = stevejobs\npassword = apple\nhosts = localhost\ndbname = mailserver\nquery = SELECT destination FROM virtual_aliases WHERE source='%s'\n<\/code><\/pre>\n<p>Here I tried to change <code>hosts = 127.0.0.1<\/code> but it says <code>warning: connect to mysql server 127.0.0.1: Can't connect to MySQL server on '127.0.0.1' (110)<\/code><\/p>\n<p>So, I am lost and don&#8217;t know where else to change in order to solve the problem. Any help would be appreciated highly.<\/p>\n<p>Thank you.<\/p>\n<p><strong>EDIT 1<\/strong><\/p>\n<p>When I do netstat -na I see that mysql is not bind neither to localhost nor to 127.0.0.1. Could it be the problem also?<\/p>\n<pre><code>bakhtiyor@ns1:~$ netstat -na | grep 3306\ntcp        0      0 0.0.0.0:3306            0.0.0.0:*               LISTEN   \n<\/code><\/pre>\n<ol>\n<li>\n<p>It seems very stupid but I have solved the problem. I hadn&#8217;t noticed that a system administrator somehow blocked 3306 port for all hosts at the firewall, and therefore I couldn&#8217;t connect to mysql. After removing that restriction I was able to connect to mysql without any problems. Thanks for your suggestions and help.<\/p>\n<\/li>\n<li>\n<p>Have you tried to connect to the Mysql server?<\/p>\n<pre><code>mysql -u username -p\n<\/code><\/pre>\n<p>Also, you can try change the listen address in \/etc\/mysql\/my.cnf to 127.0.0.1 and restart MySQL<\/p>\n<pre><code># \/etc\/mysql\/my.cnf\nbind-address = 127.0.0.1\n<\/code><\/pre>\n<\/li>\n<li>\n<p>I had a similar problem. Changing &#8220;hosts = localhost&#8221; to &#8220;hosts = 127.0.0.1&#8221; and setting bind-address to the same address fixed it for me (bind-address was set at 0.0.0.0 for some reason)<\/p>\n<\/li>\n<li>\n<p>I was just getting this same error on one of the company computers.<\/p>\n<pre><code>Can't connect to local MySQL server through socket '\/var\/run\/mysqld\/mysqld.sock' (2)\n<\/code><\/pre>\n<p>I was also getting this error a lot when I tried to run X-windows programs through ssh:<\/p>\n<pre><code>GConf Error: Failed to contact configuration server; \nsome possible causes are that you need to enable TCP\/IP networking for ORBit,\nor you have stale NFS locks due to a system crash\n<\/code><\/pre>\n<p>Turns out I had a root file system that was completely filled up, with no free disk space, so my system couldn&#8217;t write a lot of necessary files. I was getting all sorts of errors, related to many different programs. (Couldn&#8217;t log in through GDM, GDM wallpaper went black, gconf lock file errors, etc&#8230;)<\/p>\n<p>All I did was enter this simple command to get rid of over 400 MB worth of files in the root partition that were no longer needed.<\/p>\n<pre><code>sudo apt-get autoremove\n<\/code><\/pre>\n<p>That gave my root file system the breathing space it needed. Now everything runs great. Guess a 10 GB root directory isn&#8217;t enough to handle over two years worth of Ubuntu updates.<\/p>\n<p>If anybody cares, the system has been running Ubuntu 10.04 since it came out. The system updates at least once a week. Today&#8217;s date is 9-6-2012, so that&#8217;s almost 2 1\/2 years worth of updates.<\/p>\n<\/li>\n<\/ol>\n<p id=\"rop\"><small>Originally posted 2014-01-02 12:06:17. <\/small><\/p>","protected":false},"excerpt":{"rendered":"<p>I have mailserver configure using dovecot+postfix+mysql and it was runnig fine in the server(Ubuntu Server). But during last week it stopped working correctly. It doesn&#8217;t send email. When I try to telnet localhost smtp I&#8217;m connecting successfully but when I do mail from: and hit Enter it hangs on, nothing happen. Having reviewed \/var\/log\/mail.log file [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-2114","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/2114","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=2114"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/2114\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=2114"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=2114"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=2114"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}