Can’t connect to local MySQL server through socket…error.

Posted on Friday the 21st of September, 2007 at 6:08 am in Asides, Computers, Dev, Linux

I recently moved my /home folder to its own partition, but in doing so, I broke MySQL. The full error I got was:
Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)

To fix this you need to create the file and make sure that MySQL has access to it. (All commands need to be run as root)

Create the directory (if it doesn’t already exist).

sudo mkdir /var/run/mysqld/

Create the file by “touching” it.

sudo touch /var/run/mysqld/mysqld.sock

Set the ownership of the mysqld.sock file and folder to mysql.

sudo chown -R mysql /var/run/mysqld/

You can then start MySQL and breath easier.

Related posts

  1. razman posted the following on February 25, 2009 at 8:36 pm.

    i’ve followed your instruction, then it came out like this

    root@razman-laptop:~# mysql -u root -p
    Enter password:
    ERROR 2002 (HY000): Can’t connect to local MySQL server through socket ‘/var/run/mysqld/mysqld.sock’ (111)

    Reply to razman
    1. Brendan Lewis posted the following on May 9, 2009 at 6:41 am.

      I had the same problem and got the same error as razman after this ‘fix’

      Reply to Brendan Lewis
  2. Marius posted the following on June 30, 2009 at 3:05 pm.

    I have same problem…
    Same answers again and again.
    Again another unsolved problem. Noone seems to investigate what the heck is going on.
    It seems the OS have to be reinstalled.

    Ubuntu for Human DOING!

    Reply to Marius
  3. Prashant Agarwal posted the following on November 5, 2009 at 12:26 pm.

    The provided solution works when I logged in as root but when I logged in as another user I face the same error. Dont know what the problem is.. :(

    Reply to Prashant Agarwal
  4. govind posted the following on November 20, 2009 at 6:09 am.

    i killed the mysqld process, and restarted mysql, it created mysqld.sock file automatically

    everything works fine

    Reply to govind

Leave a reply

:) :D :( :o 8O :? 8) :lol: :x :P :oops: :cry: :evil: :twisted: :roll: ;) :!: :?: :idea: :arrow: :| :mrgreen: