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

Suraj picture Suraj · Dec 14, 2015 · Viewed 96.5k times · Source

I have installed LAMP on my Ubuntu machine.

Where Apache2 and PHP5 have been installed properly as when I run apache2 -v and php5 -v I am getting their installed versions.

But I am not sure how do I check If My-SQL is properly installed or not.

Because when I run mysql -u root -p command, I am getting the below error.

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

Please help!

Answer

Khalil Meg picture Khalil Meg · Oct 8, 2016

try to force redefining the root password:

sudo  service mysql stop

sudo /usr/bin/mysqld_safe --skip-grant-tables &

mysql -h localhost

(now we are using mysql without carring to user privileges)

> USE mysql

> UPDATE mysql.user
SET authentication_string=PASSWORD('new_password')
WHERE user='root' AND host='localhost';

> quit

sudo mysqladmin shutdown

sudo service mysql start

that's all ... now try to use mysql with the new password, like that:

mysql -uroot -p
Enter password: enter the new_password

it should work :)