How to Skip Name Resolve in MySQL 8 and Use IPs Instead

MySQLmysql8

I'm trying to disable the DNS name resolving as I have many other servers connecting to the central database. The DNS resolving is slow and can apparently be disabled like this:

[mysqld]
pid-file        = /var/run/mysqld/mysqld.pid
socket          = /var/run/mysqld/mysqld.sock
datadir         = /var/lib/mysql
log-error       = /var/log/mysql/error.log
port=3412
max_connections=500
skip-name-resolve

However I still can connect to it via localhost, which doesn't make sense to me.

mysql -h localhost -u root -p -P 3412

I have done some research here:

If you choose to use skip-name-resolve, make sure your MYSQL
connection privileges are set to allow IPs, and not hosts.

On most systems, for the local MySQL Server you will need to use
host=127.0.0.1 for ipv4 and host=::1 for ipv6 networks, instead of
the classic “host=localhost”.

Why can I still connect via localhost if DNS resolving is disabled?

Best Answer

MySQL treats connecting to localhost specially. In this case it connects via a UNIX domain socket, not via TCP, and the string localhost is still used for user authentication.

Related Topic