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, LinuxI 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.sockSet 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.


i’ve followed your instruction, then it came out like this
root@razman-laptop:~# mysql -u root -p
Reply to razmanEnter password:
ERROR 2002 (HY000): Can’t connect to local MySQL server through socket ‘/var/run/mysqld/mysqld.sock’ (111)
I had the same problem and got the same error as razman after this ‘fix’
Reply to Brendan LewisI 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 MariusThis 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 nickThe 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 Agarwali killed the mysqld process, and restarted mysql, it created mysqld.sock file automatically
everything works fine
Reply to govindI 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
php installer/index.php -u mozillanerd -p #GAL#GAL -d mozillanerd -x mozOops! Something went wrong during the installation:==> Unable to connect to the database.Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (111)For help you can try:* The Gallery 3 FAQ - http://codex.gallery2.org/Gallery3:FAQ* The Gallery Forums - http://gallery.menalto.com/forum** INSTALLATION FAILED **nothing seems to work.
Reply to mozillanerdActualy the OS is deleting this file each time u create it… this is weird
Reply to luckyhello, 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!
Reply to Zeeshan MalikZ.
My solution: Install the server, not just the client.
Reply to David Rodríguez