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
    1. nick posted the following on June 15, 2010 at 7:06 am.

      This is the problem with free stuff… You have to self service yourself waisting 3 – 4 days reading and posting to figure out why a file might just disapear alone. This thing just happened to me and that’s why i ended here.

      Cheers everybody, may the Varchaaar be with u all !

      Reply to nick
  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
  5. mozillanerd posted the following on April 2, 2010 at 1:47 pm.

    I have tried creating the file with owner mysql,
    I have tried stopping and restarting mysql – using the XAMPP command /opt/lampp/lampp startmysql
    The CD collection in XAMPP works fine with mysql.
    I am trying to install gallery3 with the command

    1. php installer/index.php -u mozillanerd -p #GAL#GAL -d mozillanerd -x moz
    2. Oops! Something went wrong during the installation:
    3. ==> Unable to connect to the database.
    4. Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (111)
    5. For help you can try:
    6. * The Gallery 3 FAQ - http://codex.gallery2.org/Gallery3:FAQ
    7. * The Gallery Forums - http://gallery.menalto.com/forum
    8. ** INSTALLATION FAILED **
    9. Use the following to copy and paste the code.

    nothing seems to work.

    Reply to mozillanerd
  6. lucky posted the following on May 30, 2010 at 10:05 am.

    Actualy the OS is deleting this file each time u create it… this is weird

    Reply to lucky
  7. Zeeshan Malik posted the following on July 22, 2010 at 3:08 am.

    hello, I stumbled upon the same problem… tried all the conventional solutions of creating mysqld.sock and changing the ownership to mysql user, but that was not the problem…

    On closer look in /var/log/syslog i found following error…

    mysqld[29562]: 100722 0:58:31 [ERROR] /usr/sbin/mysqld: unknown option ‘–skip-federated’
    mysqld_safe[29565]: ended
    /etc/init.d/mysql[29733]: 0 processes alive and ‘/usr/bin/mysqladmin –defaults-file=/etc/mysql/debian.cnf ping’ resulted in
    /etc/init.d/mysql[29733]: ^G/usr/bin/mysqladmin: connect to server at ‘localhost’ failed
    /etc/init.d/mysql[29733]: error: ‘Can’t connect to local MySQL server through socket ‘/var/run/mysqld/mysqld.sock’ (2)’
    /etc/init.d/mysql[29733]: Check that mysqld is running and that the socket: ‘/var/run/mysqld/mysqld.sock’ exists!

    I was setting up mysql for Ruby On Rails for which I had to install some client mysql libraries as explained at http://www.bin-co.com/blog/2009/04/error-connection-mysql-ruby-rails-linux-solution/

    ’sudo apt-get install libmysqlclient15-dev libmysqlclient15off libmysql-ruby’

    but above installations made some changes to mysql conf file and probably added ‘–skip-federated’ to my.cnf

    Removing –skip-federated solved my problem.

    Cheers!
    Z.

    Reply to Zeeshan Malik
  8. David Rodríguez posted the following on August 24, 2010 at 3:56 pm.

    My solution: Install the server, not just the client.

    Reply to David Rodríguez

Leave a reply

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