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

I don't know how many of you faced this silly error when running mysql.

mysql -u root -p"" 
Enter password: 
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
hongo@xcalibur:/opt/lampp/bin$ 

If you have MySQL server installed on your box, and also LAMPP, then you have 2 different MySQL servers on your box.

One is the system wide installation and the other one is installed under /opt/lampp/bin.

So if u run 'mysql' in the terminal you are running the system wide installation under /usr/bin/, and that's why you cannot connect to the LAMPP Mysql server instance.

If you need to connect to the LAMPP MySQL server change directory to /opt/lampp/bin/ or just run the entire line as this. 

sudo /opt/lampp/bin/mysql -u root -p"YOURPASSWORDHERE" "databasenameoptional"

ALSO MAKE SURE YOU HAVE THE SERVER RUNNING.

LAMPP SERVER AS THIS:
/opt/lampp/lampp startmysql

SYSTEM WIDE INSTALLATION:
/etc/init.d/mysql start

No comments:

Post a Comment

2 ads