53
votes

I've installed Git (bash?) from www.git-scm.com I also have a working installation of MySQL. I'm using windows 8.1. The path to my mysql bin directory IS in my path environment variable, and the mysql service IS running.

If i open cmd.exe and type in mysql -u root then it logs me in successfully, I get the "welcome to mysql monitor" message, and i can start typing sql away.

However in Git bash, if I type in mysql -u root then it just starts a new blank link and doesn't do anything.

If i type in mysql -? then i still get the mysql help information. If i type in mysql start, I get the Access denied for user ''@'localhost' to database 'start'.

How can I access mysql properly in git bash?

Please see my crude image explaining my situation below:

enter image description here

3
That sounds like it has actually started the mysql client, but the terminal is behaving the way it would if the login had no TTY (non-interactive session). If you typed a query on the blank line and terminated it correctly, MySQL would probably produce some output as though it was reading the stream from stdin. I don't know much about git bash though to recommend how to correct that. - Michael Berkowski
Thanks for your comment, unfortunately i'm a beginner at git bash too, and am trying to streamline my environment! I'll keep trying. - Phil Cross
If git-bash is based on MinGW, you may be seeing a symptom of this code.google.com/p/mintty/issues/detail?id=158 Sorry I don't know more to confirm it. - Michael Berkowski
It does sound like the issue. I'll just switch between git-bash and cmd for the time being. Thanks for your help :) - Phil Cross
Ditto this. With no password in git console, I get "ERROR 1045 (28000): Access denied for user..." as expected. With the correct password, nothing happens. Works fine in windows command prompt. I do believe it is probably a git console setting, but I couldn't say which. I don't recall this happening on previous git console versions. - Ixalmida

3 Answers

109
votes

I had the same problem with git bash and mysql, and solution to this is to use

winpty mysql -u root

I guess this is because you are running mysql for windows, using unix environment, and as far as I know winpty should be used for running windows applications in the git bash (not 100% sure, maybe someone can confirm).

3
votes

A Quick fix for other users facing that issue too:

You can create a .bash_profile to config git bash, to always use winpty by default :

cd ~ && echo "alias mysql=\"winpty mysql\"" > .bash_profile

if you already have a .bash_profile in your user folder use this command instead:

cd ~ && echo "alias mysql=\"winpty mysql\"" >> .bash_profile
2
votes

Create a shortcut in Windows Desktop with this destination:

"C:\Program Files\Git\usr\bin\mintty.exe" -e "C:\Program Files\Git\usr\bin\winpty.exe" "C:\Program Files (x86)\MariaDB 10.1\bin\mysql.exe" -uroot -p