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
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
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:
to the file
On some installations of Cygwin, specifying the host with
-h might not be enough. If so, try also specifying:
to the config file.
Assuming that you have a native Windows build of MySQL, there is a terminal emulation incompatibility between
DOS (command prompt) windows and
bash. The prompt for
mysql isn’t showing up.
To confirm this, type a command and return – it will probably work, but the prompt and the echo of the command (what you’re typing) is getting lost.
There may be a workaround in either the
CYGWIN sytem properties or in
bash, but I’ve never taken the time to work this one out.
Other answers lack the following key detail:
Cygwin has two shells:
The Win32 MySQL can write properly to #2, but not #1, because Win32 MySQL cannot probe stdin properly (thanks @PeterNore)
Want to know if you’re using Win32 MySQL? Use
$ which mysql /cygdrive/c/Program Files/MySQL/MySQL Server 5.1/bin/mysql
I posted a solution/workaround here:
Run bash from the cmd.exe executable and then mysql will work inside bash.
- Create a shortcut for cmd.exe on your desktop.
- Open up the properties for the shortcut and change the startup directory to the cygwin bin directory (usually C:cygwinbin).
- Add “/c bash.exe” to the end of the command in the target parameter.
This will run bash under the windows cmd.exe environment and when you attempt to run mysql it will execute as you would expect. This is working under windows 7 but has not been tested in any other version.
- Put cygwin bin directory in path env variable.
- Use command window by running cmd
- Run bash -l in cmd window
Then MySQL can be run without problem.
Svend Hansen’s answer is the right one:
- Install windows mysql server files (from mysql-5.5.25-win32.msi for example)
- Install Cygwin mysql client with cygwin installer (setup.exe)
- Connect to your server in a cygwin window using cygwin client “mysql -u -p[Password] -h[host]”, in my case “mysql -uroot -pXXXX -h127.0.0.1”
I think that when the question was posted, the cygwin setup did not provide mysql components, which is solved now.
Althoug Svend Hansen answer has some points, another thing is the PATH in Environment variables – if the path to mysql is before that of cygwin
/cygdrive/c/Program Files/MySQL/MySQL Server 5.5/bin/mysql
otherwise it will show the cygwin client.
As reference Wikipedia says:
Some programs may add their directory to the front of the PATH
variable’s content during installation, to speed up the search process
and/or override OS commands.
- Download Cygwin
- Install mysql client app
create an alias in .bashrc file
alias mysql=’mysql -h 127.0.0.1′
- execute source .bashrc
Now you can connect to mysql
mysql -u user -p
I have created a semi-fix for this that satisfies me.
I ran cygwin.bat in cmd.exe, then typing mysql in- everything worked fine.
I realized right there that the problem was mintty.
Easy solution? Download Console2, and under settings you can point
it to the cygwin shell. Restart Console2, run mysql and the output
This is advantageous anyways, because Console2 has a more robust interface/customization than Mintty. I really like the transparency and color mapping options.
- just copy ur mysql.exe from C:Program FilesMySQLMySQL Server 5.5bin
- paste this mysql.exe in C:cygwinusrlocalbin
- now run which mysql, It will
Disclaimer: The following solved this issue for me under MinTTY on MinGW/MSYS. From research, I believe this same root cause affects Cygwin as well.
Answer is posted here: https://stackoverflow.com/a/23164362/1034436
In a nutshell, you’ll need to prepend your
mysql command with winpty’s
console.exe (or have aliases that does so). This solution worked with native Windows MySQL executables and not a special cygwin/mingw build. You do, however, have to compile winpty, but that was simple and painless, and worked as per their documentation for me.
Note: This also solved my issue with several other native Windows console applications, namely Python and Mercurial with OpenSSH.
Reinstall cygwin and during reinstallation search for mysql in packages, install the mysql client and then it would work fine.
Found this question today 2018-03-18 looking for some answers to
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysql.sock' (2 "No such file or directory")
/etc/my.conf references config files in
I added this to
[client] host=127.0.0.1 protocol=tcp
After that I was able to access the local windows MySQL instance from a cygwin terminal using
mysql -u root -p