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


If you are trying to connect mysql using password or without password
like mysql -uUSERNAME or mysql -uUSERNAME -pPASSWORD
and getting error:-  
Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)

find first socket location
sudo find / -type s
my be location would be /tmp/mysql.sock

just go in the mysql file my.cnf
sudo nano  /etc/mysql/my.cnf

and do changes in scocket
port            = 3306
socket          = /tmp/mysql.sock

[mysqld_safe]
socket          = /tmp/mysql.sock
nice            = 0

Restart mysql, sudo /etc/init.d/mysql restart

And try login again mysql -uUSERNAME
Hope it will work.

Command to know all the mysql variable
sudo mysqladmin variables

To know mysql socket path
mysqld --verbose --help | grep ^socket

Comments

Popular Posts

How to pass hash in Postman

nginx: unrecognized service

Bootstrap Select Picker append add new item if search not exist

Reading Excel Sheets using "Roo" gem in ruby on rails

Add CORS to Nginx on AWS Elastic Beanstalk

Enable gzip compression on Elastic Beanstalk with nginx

Get video duration by URL in Ruby on Rails

site-enables nginx setting in ruby in rails