connecting to mysql from cygwin

前端 未结 14 1676
时光说笑
时光说笑 2020-12-07 22:08

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\\ Serve         


        
相关标签:
14条回答
  • 2020-12-07 22:45

    Reinstall cygwin and during reinstallation search for mysql in packages, install the mysql client and then it would work fine.

    0 讨论(0)
  • 2020-12-07 22:47
    1. Put cygwin bin directory in path env variable.
    2. Use command window by running cmd
    3. Run bash -l in cmd window

    Then MySQL can be run without problem.

    0 讨论(0)
  • 2020-12-07 22:49

    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.

    0 讨论(0)
  • 2020-12-07 22:52

    I posted a solution/workaround here:

    enter key sometimes not recognized in windows apps under cygwin

    0 讨论(0)
  • 2020-12-07 22:55

    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.

    0 讨论(0)
  • 2020-12-07 22:55

    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 appears.

    This is advantageous anyways, because Console2 has a more robust interface/customization than Mintty. I really like the transparency and color mapping options.

    0 讨论(0)
提交回复
热议问题