3
votes

I installed (on Ubuntu 13) MYSQL using

sudo apt-get install mysql

But after running

mysql -u root -p

and entering the password it gives the error

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

Please guide...

6
sometimes I have had problems connecting with socket file, try with mysql -uroot -p -h 127.0.0.1 or localhost instead of 127.0.0.1sites
another thing you can check is mysqladmin variables | grep -i socketsites
It again gives the same error..user3382201
Check if the service is even running, ps aux | grep mysqlGeoffrey

6 Answers

6
votes

Problem:

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

Solution:

sudo service mysql start
4
votes

I solved it by stopping the apache server first and restarting the mysql server

  1. sudo service apache2 stop
  2. sudo service mysql stop
  3. sudo service mysql start
  4. sudo service apache2 start
2
votes

Hope this can help you (Env: docker ubuntu16.04 container):

i run this code each time restart mysql server, it work for me:

  sudo chown -R mysql:mysql /var/lib/mysql /var/run/mysqld
  sudo service mysql start
2
votes

Make sure that Mysql is installed, still able to reproduce the issue, Look for the file in sql/my.cnf file.

Verify that the Socket connection path in that file:

  • Location shown in the error is: /var/run/mysqld/mysqld.sock

  • Actually location in my.conf file : /home/user/mysql/tmp/mysqld.sock

    home/sql/bin >> mysql -u root -p --socket=/home/user/mysql/tmp/mysqld.sock

In some version's you may find 'mysql.sock' instead 'mysqld.sock'

0
votes

I know it's too late, but I had same problem today. It solved by removing current mysql and reinstalling mariadb. It worked for me.

sudo apt install mariadb-server

-3
votes

Create one micro instance swap space in Ubuntu

dd if=/dev/zero of=/swapfile bs=1M count=1024

mkswap /swapfile

swapon /swapfile