mysql-simple icon indicating copy to clipboard operation
mysql-simple copied to clipboard

Localhost forces socket even when path is set to ""

Open LeviSchuck opened this issue 10 years ago • 1 comments

It's annoying to have to use "0.0.0.0" because using "localhost" forces it to try to use a socket, even if it doesn't exist.

If you're going to try to use the socket and be helpful, don't fail if we provide a port.

LeviSchuck avatar May 10 '14 21:05 LeviSchuck

I looked into this a little and it seems that this is actually a MySQL quirk. A couple lines from the docs:

  • If host is NULL or the string "localhost", a connection to the local host is assumed:
  • On Unix, the client connects using a Unix socket file. The unix_socket parameter or the MYSQL_UNIX_PORT environment variable may be used to specify the socket name.

So it doesn't seem to be the fault of mysql-simple.

However, I was confused that even when I pass connectOptions = [Protocol TCP] in the ConnectInfo, it still tries to use the socket. I would have thought that this option would be the same as --protocol=tcp when using the MySQL CLI client. Indeed, the docs also say

  • You can also influence the type of connection to use with the MYSQL_OPT_PROTOCOL or MYSQL_OPT_NAMED_PIPE options to mysql_options().

I see that mysql_options is theoretically getting called as part of the connect process in the wrapper library below this one:

https://github.com/paul-rouse/mysql/blob/master/Database/MySQL/Base.hs#L286

Is it possible there's some problem passing the connect options to MySQL? I'll keep looking into this...

thomasjm avatar Mar 25 '19 11:03 thomasjm