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
rivetweb opened this Issue Aug 3, 2016 · 11 comments

Comments

Projects
None yet
@rivetweb

rivetweb 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

This comment has been minimized.

Show comment
Hide comment
@dethoma

dethoma Aug 3, 2016

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

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?

@rivetweb

This comment has been minimized.

Show comment
Hide comment
@rivetweb

rivetweb 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

rivetweb 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

This comment has been minimized.

Show comment
Hide comment
@Marlinc

Marlinc 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

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

This comment has been minimized.

Show comment
Hide comment
@fpqc

fpqc Aug 3, 2016

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

fpqc commented Aug 3, 2016

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

@rodrymbo

This comment has been minimized.

Show comment
Hide comment
@rodrymbo

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

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

This comment has been minimized.

Show comment
Hide comment
@Questler

Questler Aug 7, 2016

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

Questler commented Aug 7, 2016

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

@ricksanchez

This comment has been minimized.

Show comment
Hide comment
@ricksanchez

ricksanchez Aug 12, 2016

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 ;)

ricksanchez commented Aug 12, 2016

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

This comment has been minimized.

Show comment
Hide comment
@GERMANOCARELLA

GERMANOCARELLA Oct 12, 2016

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

GERMANOCARELLA commented Oct 12, 2016

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

@jackchammons jackchammons added the mysql label Oct 25, 2016

@internetlab

This comment has been minimized.

Show comment
Hide comment
@internetlab

internetlab 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

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

@rivetweb rivetweb closed this Jun 13, 2017

@clementb

This comment has been minimized.

Show comment
Hide comment
@clementb

clementb Jun 15, 2018

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.

clementb commented Jun 15, 2018

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

This comment has been minimized.

Show comment
Hide comment
@williamsconcepts

williamsconcepts Sep 7, 2018

i want to know if i can use XAMPP for laravel

williamsconcepts commented Sep 7, 2018

i want to know if i can use XAMPP for laravel

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment