It's a common error, but all the answers don't solve my problem :

When I start mysql, I have :

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

So after reading some answers, I change it in my.cnf to /var/lib/mysql/mysql.sock and also /tmp/mysql.sock but I have the same issue each time.

In desperation, I remove mysql.sock in /var/run/mysqld, but it's not created when I do mysqld start or service mysql start (after stopping each).

I'm on Ubuntu 10.04, with a LAMP server.


  • How did you install mysql? Package or source?
    – lg.
    Aug 13, 2010 at 13:23
  • ubuntu package (via apt-get).
    – Dorian
    Aug 13, 2010 at 14:16

2 Answers 2


Check the permissions on those directories or that the file was in use.

Here's a permission scenario. Suppose that you install MySQL and are playing around as root, you manage to start the database and accidentally get it to write in the /tmp directory a named socket with root ownership. You kill the process in a violent way and cleanup doesn't happen.

Then, later, you try as a regular user to get MySQL to start, which may want to use a special mysql user the distro put on your system. Because the named socket exists, it fails. Because it doesn't have permission to zap root's cruft, that fails.

Then you reboot, which can wipe all of /tmp before the system starts. Now there's nothing there, the MySQL server comes up, no conflicts, and magically it all appears to work.

Not saying this is what happened, but most of my woes when something happened like this turned out that some directory didn't have write permission along the way or the file was already there and couldn't be deleted by a mortal account.

Glad to hear you got it fixed, though.


Problem solved : I restart my server and it works fine :) (wtf ?).

Relevant Commands:

/etc/init.d/mysqld restart
/etc/init.d/mysqld stop
/etc/init.d/mysqld start
  • Don't forget to accept your answer (when you can), then the Community User won't bump the question in future.
    – ChrisF
    Aug 13, 2010 at 14:21
  • It's also not required to add "[solved]" to the title -- Accepting an answer, as ChrisF describes, denotes this.
    – jscott
    Aug 13, 2010 at 14:29
  • What's the difference, marked it answered or not doesn't appear in searches or "Related" list anyway Aug 13, 2010 at 15:12
  • I have "You can accept your own answer in 2 days".
    – Dorian
    Aug 13, 2010 at 22:42

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .