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

September 30, 2014 295.6k views

I currenty have a LAMP, running on Ubuntu 14.04, yesterday everything was fine, but today my MYSQL is not working.

When i try to connect via

mysql -u root -p

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

the Mysql.err file is completely empty, and have absolute no ideia about what to do.

3 comments
  • Is it running?

  • I think you didn't started your database server, start it using

    #services mysql start
    or 
    #/etc/init.d/mysql start
    
    

    If you are getting a failure message while starting, check the log file (/var/log/syslog), if you found socket connection error message there, then
    check for correct socket file location #find / -type s, if you found a mysqld.sock file under /var/run/mysqld/ directory, check whether any instances of mysqld running or not #netstat -anpt | grep 3306 or #ps aux | grep mysqld if you found any running process stop it (#kill -9 pid) and remove the socket file. Then try to restart it and if mysql not creating socket file then try start it like

    #/usr/sbin/mysqld --defaults-file=/etc/mysql/my.cnf --basedir=/usr --datadir=/var/lib/mysql --pid-file=/var/run/mysqld/mysqld.pid --socket=/var/run/mysqld/mysqld.sock
    

    Also check your my.cnf file (/etc/mysql/my.cnf) and comment the bind-address field, and if you found any skip-network field comment it.

    regards,
    sreejith kb

  • /etc/init.d/mysql start

    worked for me. I am using kali linux. thank you lots.

10 Answers

I had the same problem and i solved it restarting the mysql server.

sudo service mysql restart

I tried to reboot my server, and now its completely off.

Problem solved, basically i had to purge and reinstall mysql. Using this http://stackoverflow.com/questions/22909060/mysql-job-failed-to-start

  • purging and re-installing is not a solution to that particular problem, its an easy way to escape from that prob., but some times because of 'time limitation' we have to do it.

does it mean my server is under attack? I saw a lot of bots crawling in my server... or it's only a system failure? after rebooting my server it's normal again.

Killed 5 hours trying to figure out what causes the error. The solution was stupid simple, I just needed to free up some disk space on my droplet. I had a few huge log files that had eaten up all the free space so mysql simply couldn't start and gave me the ERROR 2002 (HY000). Check how much free space you have by doing *df -h * command in terminal.

derek_tgm's reply fixed the problem. I had copied a droplet and couldn't start MySQL, and had the same error message. Increasing the server resources fixed it for me.

If you are creating a droplet from snapshot, then make sure to update the bind-address field with the new ip address.

$sudo nano /etc/mysql/my.cnf

Update the bind-address field with new ip address then run

$sudo service mysql start

My problem was running out of memory. Digital ocean has great instruction for adding swap memory for Ubuntu: https://www.digitalocean.com/community/tutorials/how-to-add-swap-on-ubuntu-14-04

This solved the issue and enabled me to restart the Mysql that otherwise would not start.

by Justin Ellingwood
Swap space can be used as an "overflow" area for your system when you run out of RAM. The operating system can store data that would normally be kept in RAM on the hard drive in a specially formatted file. In this guide, we'll demonstrate how to create and use one of these files in Ubuntu 14.04.
Have another answer? Share your knowledge.