Connect to mysql from cygwin

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

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

What's wrong?

+52
mysql cygwin
Dec 01 '08 at 2:26
source share
13 answers

Assuming you have a built-in build of Windows MySQL, there is incompatible terminal emulation between DOS (command line) and bash windows. mysql query is not displayed.

To confirm this, enter the command and return - it will probably work, but the request and echo of the command (what you type) are lost.

There may be a workaround in the properties of the CYGWIN sytem or in bash , but I never wasted time on this.

+15
Dec 01 '08 at 3:19
source share

I just came across this, and when I read that someone mentioned that this is the Windows / DOS command that you run in cygwin, I did which mysql and gave me:

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

So, I ran cygwin Setup.exe to search for "mysql" and installed the last "mysql client". Now which mysql looks like this:

 $ which mysql /usr/bin/mysql 

And the MySQL team works in cygwin :)

Although this is an old question, it would be nice to have a real answer here, as people (like me) can still stumble upon it.

If your attempts to start 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) 

You can then fix this by adding explicit parameters -h 127.0.0.1 to the command line, for example:

 $ mysql -u root -p -h 127.0.0.1 

Comments based updates:

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

 [client] host=127.0.0.1 

to the file /etc/my.cnf

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

 --protocol=tcp 

or add

 protocol=tcp 

to the configuration file.

+65
Apr 03 2018-12-12T00:
source share

Other answers lack the following key detail:

Cygwin has two shells:

  • Default: c:\cygwin\bin\mintty.exe
  • Primary: c:\cygwin\Cygwin.bat (which runs c:\cygwin\bin\bash.exe )

Win32 MySQL can write # 2 correctly, but not # 1, because Win32 MySQL cannot correctly examine stdin (thanks @PeterNore)

Want to know if you are using Win32 MySQL? Use which , for example.

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

Bonus: Cygwin's Guide to Overcoming Path Challenges ( thanks to @Dustin )

+6
Jul 15 '13 at 12:59 on
source share

I posted the solution / workaround here:

enter a key that is sometimes not recognized in windows applications in cygwin

+5
Dec 02 '08 at 17:54
source share

Run bash from the cmd.exe executable, and then mysql will work inside bash.

  • Create a shortcut for cmd.exe on your desktop.
  • Open the properties for the shortcut and change the startup directory to the cygwin bin directory (usually C: \ cygwin \ bin).
  • Add "/ c bash.exe" to the end of the command in the target parameter.

This will start bash in the windows cmd.exe environment, and when you try to start mysql, it will run as you expected. This works under Windows 7 but has not been tested in any other version.

+4
Jan 05 '12 at 13:52
source share
  • Put the cygwin bin directory in the env variable of the path.
  • Use command window by running cmd
  • Run bash -l in cmd window

Then MySQL can be started without problems.

+2
Apr 09 '12 at 18:03
source share

Svend Hansen's answer is correct:

  • Install mysql windows server files (e.g. from mysql-5.5.25-win32.msi)

  • Install the cygwin mysql client with the cygwin installer (setup.exe)

  • Connect to your server in the cygwin window using the cygwin client "mysql -u [user] -p [Password] -h [host]", in my case "mysql -uroot -pXXXX -h127.0.0. 1"

I think that when the question was submitted, the installation of cygwin did not provide the mysql components that are now being resolved.

+1
Jun 06 '12 at 12:18
source share

I created a semi-fixed for this that satisfies me. I ran cygwin.bat in cmd.exe, then typing mysql, everything worked fine.

I realized that the problem was unfair.

A simple solution? Download Console2 , and under the settings you can point it to the cygwin shell. Restart console2, start mysql and output appears.

In any case, this is beneficial because Console2 has a more reliable interface / configuration than Mintty. I really like the transparency and color options.

0
Jan 28 '13 at 22:52
source share

Do it:

  • just copy ur mysql.exe from C: \ Program Files \ MySQL \ MySQL Server 5.5 \ bin
  • paste this mysql.exe into C: \ cygwin \ usr \ local \ bin
  • now start mysql, it will be
0
Sep 25 '13 at 10:11
source share

Althoug Svend Hansen's answer has a few points, the other is the PATH variables in the environment - if the path to mysql is before Cygwin

 which mysql 

will show

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

otherwise, it will display the cygwin client.

As stated on Wikipedia:

Some programs may add their directory to the front of PATH variable content during installation to speed up the search process and / or override OS commands.

0
Feb 02 '14 at 10:24
source share

Disclaimer: The next solution to this problem is for me at MinTTY on MinGW / MSYS. From research, I believe that this same root cause also affects Cygwin.

The answer has been sent here: https://stackoverflow.com/a/316618/

In short, you need to add the mysql command using winpty console.exe (or have aliases that do this). This solution worked with native Windows MySQL executables, rather than a special build of cygwin / mingw. However, you should compile winpty, but it was simple and painless, and I worked on their documentation for me.

Note. It also solved my problem with several other built-in console Windows applications, namely Python and Mercurial with OpenSSH.

0
Apr 19 '14 at 1:07
source share
  • Download Cygwin
  • Install mysql client application

  • create an alias in the .bashrc file

    alias mysql = 'mysql -h 127.0.0.1'

  • execute .bashrc source code

Now you can connect to mysql

mysql -u user -p

0
Oct. 25 '15 at 5:56
source share

Reinstall cygwin and upon reinstalling, find mysql in packages, install the mysql client, and then it will work fine.

0
Apr 20 '16 at 18:53 on
source share



All Articles