大网数据广告活动
服务器运维问答

How to skip-name-resolve in Mysql8 and use IPs instead?

· 52CE 我爱测

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 sock…

问题原文

原帖链接 · Houman · CC BY-SA 4.0

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?

已采纳解答

原帖链接 · Michael Hampton · CC BY-SA 4.0

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.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2020-12-05)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。