Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cygwin connecting to MySQL: Can't connect to local MySQL server through socket '/var/run/mysql.sock'

Tags:

mysql

cygwin

I just installed MySQL 5.5.27 on WinXP. When I open a command prompt (Start -> Run, and type "cmd"), I can access MySQL by running "mysql -u root -p". However, when I open a Cygwin terminal and try the same thing, I get this error

$ mysql -u root -p
Enter password:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysql.sock' (2)

Indeed, there is no "/var/run/mysql.sock" file.

like image 425
Dave A Avatar asked Aug 10 '12 00:08

Dave A


People also ask

Can't connect to local MySQL server?

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 not connect to local MySQL server through socket '/ tmp 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.

Can't connect to local 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.


1 Answers

If you specify the host on the command line, this issue should go away:

mysql -u root -p -h 127.0.0.1

You can also create a my.ini that mysql will use:

echo [client] >c:\my.ini
echo user=root >>c:\my.ini
echo host=127.0.0.1 >>c:\my.ini

Then you can just type:

mysql -p

You can even add the password:

echo password="abracadabra" >>c:\my.ini

Then, just type:

mysql

and you're in!

See also https://serverfault.com/questions/337818/how-to-force-mysql-to-connect-by-tcp-instead-of-a-unix-socket

like image 117
Ross Smith II Avatar answered Sep 20 '22 18:09

Ross Smith II