1

MySQL server was installed and was running just fine. Today we can't connect to the database via our websites. Command line access using mysql -u username -p also fails. Finally, phpmyadmin fails.

ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)

service mysql restart
stop: Unknown instance:
start: Job failed to start

Error logs (/var/log/mysql/error.log & /var/log/mysql.err & /var/log/mysql.log) are all empty for the past week. The problem just began today.

I have looked at lots of answers including Ubuntu Error 2002 “Can't connect to local MySql server through socket…” and ERROR 2002 (HY000): Can't connect to local MySQL.

Should I just reinstall mysql server and chalk it up as an unknown error? (horrible idea, obviously).

What is the right course of action to fix immediately and prevent from reoccurring?

  • have you tried killing off any existing mysql processes with kill, and deleting the files under /var/run/mysqld? Or maybe rebooting? – Zoredache Apr 18 '13 at 22:36
  • Rebooting did not help. I have not tried kill nor delete. One more point... I need to maintain all mysql databases and data. – csi Apr 18 '13 at 22:43
  • Can you post the result of ps aux | grep mysql? – Spack Apr 18 '13 at 22:51
  • Added to question – csi Apr 18 '13 at 23:00
  • 1
    Make sure you are not out of diskspace. That could kill your mysql. Also, make sure your sock file is deleted. I think my.cnf will tell you where it creates the mysql.sock file. – Nikolas Sakic Apr 19 '13 at 4:05
2

I changed the bind-address from the IP to 127.0.0.1. Still not sure why this worked and then all of a sudden stopped. Here is the solution for others.

sudo nano /etc/mysql/my.cnf

change

bind-address = "127.0.0.1"

And then

sudo service mysql restart
|improve this answer|||||
  • Just one question why you restarted apache2 after changing my.cnf file? – Abhishek Anand Amralkar Apr 19 '13 at 5:25
  • Edited - did not restart apache, restarted mysql. Sorry about the typo. It is corrected. – csi Apr 22 '13 at 13:53
  • my bind address has always been set to 127.0.0.1 and this is a regular occurance on more than 1 of my servers. – Rebecca Dessonville Jan 4 '16 at 16:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.