Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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!

like image 284
Suraj Avatar asked Dec 14 '15 11:12

Suraj


People also ask

Can't connect to local MySQL server on localhost?

normally means that there is no MySQL server running on the system or that you are using an incorrect Unix socket file name or TCP/IP port number when trying to connect to the server. You should also check that the TCP/IP port you are using has not been blocked by a firewall or port blocking service.

Can't connect to MySQL server through socket Ubuntu?

"Try" to run mysql via /etc/init. d/mysql start if it gives you the exact same error from above then you need to copy the mysql. server file from the mysql you downloaded which can be found in the support-files folder inside the mysql folder you downloaded or in the /usr/local/mysql folder and copy it to /etc/init.

Can't connect to local MySQL server through socket '/ Applications Ampps var MySQL sock?

It means either the MySQL server is not installed/running, or the file mysql. sock doesn't exist in /var/lib/mysql/ . There are a couple of solutions for this error. Then try to connect again.


3 Answers

For resolving this issue, you need to run following commands sequentially

 sudo service mysql stop 
 sudo /etc/init.d/apparmor reload
 sudo service mysql start

After that you can run the following command to go to mysql console

mysql -u root -p
mysql>
like image 88
AJTech Solutions Avatar answered Oct 23 '22 11:10

AJTech Solutions


you could try starting your mysql first

> ln -s /var/lib/mysql/mysql.sock /tmp/mysql.sock
> 
> service mysql start or service mysql start
like image 38
cocoboy Avatar answered Oct 23 '22 11:10

cocoboy


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 :)

like image 43
Khalil Meg Avatar answered Oct 23 '22 10:10

Khalil Meg