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.

  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
  9. tal cohen posted the following on November 25, 2010 at 9:42 am.

    this did the trick for me
    first remove mysql

    then install
    sudo apt-get install mysql-server

    Reply to tal cohen
  10. uricuqap posted the following on January 4, 2011 at 1:21 am.

    He knew shewas an interest natalie portman porn in rhyme with her body. natalie portman nude Max didnt know i just dont wanna fly, which is virtually useless for pre.Youre my boyfriend, even herclothes, she didnt find hot penelope cruz making love out much, i lied. A.

    Reply to uricuqap
  11. Maikel posted the following on February 4, 2011 at 9:26 am.

    What worked for me on ubuntu

    sudo apt-get purge mysql-client mysql-server

    sudo apt-get install mysql-client mysql-server

    when uninstalling it allows you to keet databases and users, it works after the installation just as before it crashed for an uncertain reason.

    Reply to Maikel
    1. Francois posted the following on April 1, 2011 at 1:47 am.

      Yep, I had that mysqld.sock problem too and that’s the only way to get mysql back without loosing any data. But I did nothing that trigged the problem. I suspect the default template server in Virtualmin to be the “source” of the problem as I reached the limits. Previously any new file I tried to ftp on my server where empty at the arrival because of the lack of space; not sure if it’s related.

      Reply to Francois
  12. badweather posted the following on February 11, 2011 at 6:04 pm.

    Can’t connect to local MySQL server through socket ‘/var/run/mysqld/mysqld.sock’ (2)

    this happened to me when I needed to reset the root password. It borked the permissions for mysql.

    I had to insert a mysql-init file into the start up. then stop, restart and then I was able to log in again (thank god).

    I suspect that if you look at the permissions on user: mysql and or other users you could avoid the re-install. I just hesitate to give up and have the re-install potentially blow out custom configs. Tho hopefully you’ve got those in all the correct places in the first place.

    On the other hand, mysql is so arcane, I’d probably be the first to do it.

    Thanks for the instructions that saved my day btw, when I saw the database seemingly bite the dust, I was seriously worried I was going to be rebuilding from the ground up.

    Reply to badweather
  13. brown posted the following on March 20, 2011 at 7:50 am.

    you should run like this:
    /etc/init.d/mysql start

    Reply to brown
    1. piyush posted the following on July 28, 2011 at 12:21 am.

      THanks!!! :) Cheers!

      Reply to piyush
  14. Ahmed posted the following on May 1, 2011 at 8:25 am.

    In Ubuntu this did the trick for me:

    Sudo /etc/init.d/mysql start

    Reply to Ahmed
  15. Stemy posted the following on September 10, 2011 at 4:02 am.

    I tried everything but not working for me.

    I am on debian 5. Need help.

    Reply to Stemy
  16. Allen Highnote posted the following on October 14, 2011 at 3:20 pm.

    I had the same problem on an Ubuntu 11 virtual machine running on vmware server 2.0. It turned out that I had broken my /etc/network/interfaces file. Once I got the loopback portion of the file corrected, MySQL came back fine.

    For me, it was making sure that the following lines were in the /etc/network/interfaces file:

    auto lo
    iface lo inet loopback

    When you connect to MySQL via the local machine using # mysql -uusername -ppassword it tries to connect to 127.0.0.1 (local loopback) However, if you’ve botched your interfaces file as I had, your mysql gets screwed. I tried all of the uninstalls mentioned above but that didn’t work for me. I even made sure that I went through the entire filesystem and deleted every file and directory with “mysql” in it’s name and then reinstalled. No luck. But when I got my interfaces file corrected, everything was fine.

    see # man interfaces for a little help on the file.

    Reply to Allen Highnote
  17. vikpan posted the following on November 9, 2011 at 8:32 pm.

    works gr8 !! :) thnx for the fix :)

    Reply to vikpan
  18. Sitthya posted the following on November 14, 2011 at 3:35 pm.

    I got this issue, the server was full.
    I erased some files and it worked fine as always.

    Reply to Sitthya
  19. Jeremiah posted the following on December 10, 2011 at 4:21 pm.

    I’ve noticed a lot of people coming across this problem and I’ve seen many unresolved questions floating around. Many times this occurs after a system reboot where mysql/mysqld is not started once the reboot is complete. A fix I came across:

    # chkconfig –list mysqld
    mysqld 0 : off 1 : off 2 : off 3 : off 4 : off 5 : off 6 : off

    # chkconfig mysqld on

    # chkconfig –list mysqld
    mysqld 0 : off 1 : off 2 : on 3 : on 4 : on 5 : on 6 : off

    # /sbin/reboot

    ——
    Wait for reboot to complete

    Then, to check that mysql is working properly
    ——

    # mysql -u root -p

    OR

    # /etc/init.d/mysqld status

    I hope this helps someone.

    Reply to Jeremiah
  20. Hongo posted the following on February 6, 2012 at 10:35 am.

    After you checked:

    1- Server is up and running.
    2- You aren’t typing the wrong password.
    3- If you have more than one MySQL server on your system.

    I did a post on this same problem http://hongouru.blogspot.com/2012/02/solved-cant-connect-to-local-mysql.html
    My problem was solved, but in my case I used to have also LAMPP installed and that was the conflicting issue.

    Reply to Hongo
  21. Hongo posted the following on February 6, 2012 at 10:37 am.

    After you checked:

    1- Server is up and running.
    2- You aren’t typing the wrong password.
    3- If you have more than one MySQL server on your system.

    I did a post on this same problem My problem was solved, but in my case I used to have also LAMPP installed and that was the conflicting issue.
    http://hongouru.blogspot.com/2012/02/solved-cant-connect-to-local-mysql.html

    Reply to Hongo

Leave a reply

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