localhost doesn't work with docker but 127.0.0.1 does

956 views
Skip to first unread message

Kevin Tran

unread,
Nov 14, 2020, 11:07:12 PM11/14/20
to Sqitch Users
I'm using a mysql docker container on MacOS.  There's a weird issue that happens when I try to connect to my database.  If I use this connection string "db:mysql://root@localhost/mydb" I get an error:

Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)

If I switch "localhost" with "127.0.0.1" then it will work.

Is this a bug in MySQL/sqitch?
Is there a reason for this difference?
Are the perl libraries/database drivers programmed to assume that localhost means a socket?
Where do you look this up?
Maybe this should be documented because it is really confusing?

Dan Lynch

unread,
Nov 14, 2020, 11:11:29 PM11/14/20
to Kevin Tran, Sqitch Users
I'm almost pretty sure this is a mysql issue. I recall running into the same thing (I use PG now). It's not related to sqitch if my memory is correct.

--
You received this message because you are subscribed to the Google Groups "Sqitch Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sqitch-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/sqitch-users/6d5d4782-51ea-40b3-8a36-8ad262dad0c7n%40googlegroups.com.

Kevin Tran

unread,
Nov 15, 2020, 4:38:03 AM11/15/20
to Sqitch Users
Thanks I believe that's possible.  I get the same error message just running mysql on the command line.

I'm confused because my Python code and GUI tools connect with localhost.  They could be doing some conversion.

Diep Pham

unread,
Dec 7, 2020, 2:31:21 AM12/7/20
to Sqitch Users
On a UNIX system, mysql client will attempt to use Unix socket file if the hostname is localhost. This is documented in the official documentation (https://dev.mysql.com/doc/refman/8.0/en/connecting.html)

> On Unix, MySQL programs treat the host name localhost specially, in a way that is likely different from what you expect compared to other network-based programs: the client connects using a Unix socket file. The --socket option or the MYSQL_UNIX_PORT environment variable may be used to specify the socket name.

Reply all
Reply to author
Forward
0 new messages