Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to connect from bash to mysql (or other network services) installed in Windows? #737

Closed
xukku opened this issue Aug 3, 2016 · 15 comments

Comments

@xukku
Copy link

xukku commented Aug 3, 2016

I am try to connecting from bash mysql client to mysql server installed in windows
but it not work.

How to work with mysql (or mssql or other databases) and other windows network services from this bash ubuntu?

@dethoma
Copy link

dethoma commented Aug 3, 2016

How are you trying to connect? over a socket? Can you use the template and send us full repro details?

@xukku
Copy link
Author

xukku commented Aug 3, 2016

in bash shell i am trying this

mysql --host=localhost --user=root --password=root

and got error

ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)

but now i try this

mysql --host=127.0.0.1 --user=root --password=root

and it work for me. i can use mysql server installed on windows. but only by IP

@Marlinc
Copy link

Marlinc commented Aug 3, 2016

This is an issue in the MySQL client implementation. It automatically overrides a host set to localhost with /var/run/mysqld/mysqld.sock

@fpqc
Copy link

fpqc commented Aug 3, 2016

@Marlinc Wow, and you can't even set it like "tcp,localhost" or anything?

@rodrymbo
Copy link

rodrymbo commented Aug 4, 2016

@fpqc : I don't think the MySQL developers envisioned an environment like WSL so segregated from MySQL running as a service in Windows.

But WSL is so segregated, I would automatically assume I'd need to connect via IP rather than unix socket. Or, perhaps, figure out if the Windows service supports sockets (doubtful), and tell the mysql client in WSL where to find the socket. The default for the client is probably /var/run/mysqld/mysqld.sock which would be in VolFS, and windows programs are supposed to stay away from that. If MySQL running in Windows does listen on a socket (a socket compatible with WSL?), it would definitely be somewhere else (in DriveFS?).

The MySQL client supports an option file, where one can probably specify protocol and ip address and port and such to use for a given server. So if explicitly saying (on the command line) --protocol=TCP doesn't force --host=localhost to use TCP/IP, one can probably use some combination in an option file to force it to use the right settings, without having to remember (and type accurately) all the options each time.

@Questler
Copy link

Questler commented Aug 7, 2016

Have just installed mariadb and had same issue and after restrating the mysql service it worked.

@ricksanchez
Copy link

That is not a bug, is actually documented in mysql. Those parameters are ignored unless you add --protocol=TCP
try: mysql -uroot -p --host=localhost --port=3308 --protocol=TCP
I don't know, but at least in php mysqli localhost means unixsocket, I guess that for the mysql cli is the same, that is why an ip address solves your problem ;)

@GERMANOCARELLA
Copy link

Ok, but in mysql there is a file caled my.cnf or similar. These option annot be set in this file? I searched but I have not found my.cnf, but I'm sure there is...

@internetlab
Copy link

internetlab commented Dec 7, 2016

Using '127.0.0.1' instead of localhost, resolved the issue, think this is easy to do when connecting from a php script rather than defining the protocol.

http://stackoverflow.com/questions/6366192/specifying-protocol-in-mysql-connect-php

@xukku xukku closed this as completed Jun 13, 2017
@clementb
Copy link

As suggested @ricksanchez I had to add protocol=TCP in /etc/mysql/my.cnf

After that, I was able to connect to a XAMPP powered mysql instance from WSL.

In my app living in WSL, changing the host from localhost to 127.0.0.1 in also helped.

@williamsconcepts
Copy link

i want to know if i can use XAMPP for laravel

@matthework
Copy link

This should work. In my case, port is 3306

mysql -u root -p --host=127.0.0.1 --port=3306 --protocol=TCP

@jepzen
Copy link

jepzen commented Mar 7, 2021

I got the same problem but none of your suggestions works... not even with port and protocol. Can easily connect through Workbench installed on the Windows but not from WSL. Im using a Mysql8.0.

I downgraded to WSL 1 then it worked. Is this not supported in WSL2 ?

@blakenvicrez
Copy link

blakenvicrez commented May 13, 2022

I installed MySQL (Maria) via WAMP and used apt install mariadb-client-core-10.3 to get WSL 2 to recognize the mysql command, then used $ /mnt/c/wamp64/bin/mariadb/mariadb10.3.34/bin/mysql.exe -u root -p to connect. I got this from https://superuser.com/questions/1536619/connect-to-mysql-from-wsl2 which has instructions for another (better) way, but doesn't clearly describe what to do. Something about specifying an ip address in a configuration file I think.

@Harpreetk01
Copy link

Please tell me how to add our MySQL code from git bash to GitHub. And we need to download the MySQL code somewhere, guys please help I am confused.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests