Non-default MySQL-DB location on localhost

Hi all :slight_smile:

Quick question concerning the MySQL DB.

Background:
I had to move the MySQL DB on a monitoring system to a different folder due to a lack of space (bc the vspheredb module fills up the DB https://github.com/Icinga/icingaweb2-module-vspheredb/issues/73)
So now the Db is in a different folder than /var/lib/mysql.

(Dumb) Question: I move the datadir and socket to the new location.
Why do I need to use the IP address in the resource configureation now and can’t use “localhost” anymore? Is it hardcoded that “localhost” refers to a specific path for the socket?
Or did I just miss some setting?

System is CentOS 7 with Icinga 2.11

I’ve seen systems where localhost is not resolves to an IP address, but instead uses some internal magic to point to a unix socket instead. This is likely done for two reasons: 1) unix sockets have less packet overhead than tcp packages for the kernel 2) dns shouldn’t be involved.

In case you are working on a host, I’d always use IP addresses instead of localhost anyways.

Cheers,
Michael

Thanks for the quick answer.
Localhost resolves to 127.0.0.1.
But the “problem” is too insignificant as to dump more time into it to figure it out :smiley:
Then I will not make a big fuss about it and just use the IP.

This might be related to the authentication mechanism being used here. It’s / it can be different for connections via the unix socket.

Marcel

If i remember correctly, if you use “localhost” for the connections, mysql clients will connect to the socket. Using the ip, the client makes a tcp connection.

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. 

https://dev.mysql.com/doc/refman/8.0/en/connecting.html

2 Likes