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

Mysql connection fails when connecting to localhost. "Can't connect to local MySQL server through socket when" #478

Closed
jrz opened this issue Oct 12, 2022 · 10 comments · Fixed by #522

Comments

@jrz
Copy link

jrz commented Oct 12, 2022

Otherwise it tries to connect using a socket

@ashmaroli
Copy link
Member

@jrz Please explain your issue in detail.
What was the error message?
Did the solution posted in #376 work for you?
What version of the plugin are you using?

@jrz
Copy link
Author

jrz commented Oct 12, 2022

Exactly as #376 , jekyll 4.2.2. #376 was closed and ignored.
The problem is that when using host: localhost, it tries to connect to a unix socket.

After some digging, the problem seems to be in libmysql. Although insane, but it's mysql, so insanity is the norm. It is explained here: https://dev.mysql.com/doc/c-api/8.0/en/mysql-real-connect.html


The value of host may be either a host name or an IP address. The client attempts to connect as follows:

  • If host is NULL or the string "localhost", a connection to the local host is assumed:

    • On Windows, the client connects using a shared-memory connection, if the server has shared-memory connections enabled.

    • On Unix, the client connects using a Unix socket file. The unix_socket argument or the MYSQL_UNIX_PORT environment variable may be used to specify the socket name.

  • On Windows, if host is ".", or TCP/IP is not enabled and no unix_socket is specified or the host is empty, the client connects using a named pipe, if the server has named-pipe connections enabled. If named-pipe connections are not enabled, an error occurs.

  • Otherwise, TCP/IP is used.

You can also influence the type of connection to use with the MYSQL_OPT_PROTOCOL or MYSQL_OPT_NAMED_PIPE options to mysql_options(). The type of connection must be supported by the server.

@jrz
Copy link
Author

jrz commented Oct 12, 2022

So please update the sample code and default configuration from "localhost" into "127.0.0.1"

@ashmaroli
Copy link
Member

@jrz You never mention which importer was used though.

@jrz
Copy link
Author

jrz commented Oct 12, 2022

Oh worry, it was the wordpress importer (self-hosted), but I noticed joomla has default settings to localhost as well

@ashmaroli
Copy link
Member

@jrz Let us leave #376 in the past. This current ticket has more context thanks to your investigation and diagnosis that the issue is ultimately with libmysql.
Therefore, I request you to edit the ticket title and opening comment to best express the issue.
Since, the issue is with the database involved, I don't think simply updating one importer is going to be sufficient.

Pinging @parkr for technical inputs:

  • Do we need to make changes to all importers that use MySQL db or update just the self-hosted WP importer.
  • Some importers reuse logic between SQL db and Postgres db. Would PG db be fine with 127.0.0.1 instead of localhost?
  • Would this change be a major SemVer change or a minor SemVer change considering localhost is generally equivalent to the 127.. address..?

@jrz
Copy link
Author

jrz commented Oct 12, 2022

The problem really lies withing libmysql. I don't think postgres has this problem. I assume that Oracle doesn't change this behavior because of backwards compatibility.

Anyone who's using sockets probably hasn't changed "host" into something else. If they did, it's wrong, and also easy to detect (connnection will fail because it's trying to connect to an inet host. It'll be obvious, because the hostname is set in the configuration).

Anyone else who's using an inet connection, and has it working, is already not using "localhost", because it simply doesn't work.

There was also an issue where socket was set to "" instead of nil. It's related in terms of impact. Not sure about the versions there.

@jrz jrz changed the title Please reopen 376 Mysql connection fails when connecting to localhost. "Can't connect to local MySQL server through socket when" Oct 12, 2022
@jekyllbot
Copy link
Contributor

This issue has been automatically marked as stale because it has not been commented on for at least two months.

The resources of the Jekyll team are limited, and so we are asking for your help.

If this is a bug and you can still reproduce this error on the master/main branch, please reply with all of the information you have about it in order to keep the issue open.

If this is a feature request, please consider whether it can be accomplished in another way. If it cannot, please elaborate on why it is core to this project and why you feel more than 80% of users would find this beneficial.

This issue will automatically be closed in two months if no further activity occurs. Thank you for all your contributions.

@parkr
Copy link
Member

parkr commented Dec 12, 2022

I’m comfortable updating the defaults for MySQL-backed databases to use 127.0.0.1 for the host.

@jekyllbot
Copy link
Contributor

This issue has been automatically marked as stale because it has not been commented on for at least two months.

The resources of the Jekyll team are limited, and so we are asking for your help.

If this is a bug and you can still reproduce this error on the master/main branch, please reply with all of the information you have about it in order to keep the issue open.

If this is a feature request, please consider whether it can be accomplished in another way. If it cannot, please elaborate on why it is core to this project and why you feel more than 80% of users would find this beneficial.

This issue will automatically be closed in two months if no further activity occurs. Thank you for all your contributions.

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

Successfully merging a pull request may close this issue.

4 participants