Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
537 views
in Technique[技术] by (71.8m points)

connecting to mysql from cygwin

I can successfully connect to MySQL from a DOS prompt, but when I try to connect from cygwin, it just hangs.

$/cygdrive/c/Program Files/MySQL/MySQL Server 5.1/bin/mysql -u root -p

What's wrong?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I just came across this, and when I read someone's mention of it being a windows/DOS command that you run in cygwin I did a which mysql and that gave me:

$ which mysql
/cygdrive/c/Program Files/MySQL/MySQL Server 5.5/bin/mysql

So I ran the cygwin Setup.exe searched for "mysql" and installed the latest "mysql client". Now which mysql looks like:

$ which mysql
/usr/bin/mysql

And the MySQL command works in cygwin :)

Though it's an old question, it would be nice to have the actual answer here, as people (like myself) might still stumble across it.

If your attempts to run the MySQL client from Cygwin return the following error:

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

Then you can fix it by adding the explicit -h 127.0.0.1 options to the command line, as in:

$ mysql -u root -p -h 127.0.0.1

Updates based on comments:

To avoid specifying -h 127.0.0.1 on the command line every time you connect, you can add:

[client]
host=127.0.0.1

to the file /etc/my.cnf

On some installations of Cygwin, specifying the host with -h might not be enough. If so, try also specifying:

--protocol=tcp

or add

protocol=tcp

to the config file.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...