MySQL · 配置参数 · skip_name_resolve

参数说明

skip_name_resolve:检查客户端连接时是否解析主机名。

  • OFF:默认状态,仅在第一次建立连接时缓存 IPHost Name 的映射关系,同一主机的后续连接将直接查看 Host Cache,而不用再次进行 DNS 解析。
  • ON:禁止 DNS 解析,启用后 MySQL 授权表中就不能使用主机名了,只能使用 IP
Property Value
Command-Line Format --skip-name-resolve=#
System Variable skip_name_resolve
Scope Global
Dynamic No
Type Boolean
Default Value OFF
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
MariaDB [(none)]> show variables like 'skip_name_resolve';
+-------------------+-------+
| Variable_name | Value |
+-------------------+-------+
| skip_name_resolve | OFF |
+-------------------+-------+

MariaDB [mysql]> select user,host,password from user;
+-------------+---------------+-------------------------------------------+
| user | host | password |
+-------------+---------------+-------------------------------------------+
| root | localhost | *C655557AE3BD4264288BB5C1ED8126A364A6F7ED |
| root | hlht\_db3 | *C655557AE3BD4264288BB5C1ED8126A364A6F7ED |
| root | 127.0.0.1 | *C655557AE3BD4264288BB5C1ED8126A364A6F7ED |
| root | ::1 | *C655557AE3BD4264288BB5C1ED8126A364A6F7ED |
| read_only | % | *47646ED664BFD993442F175266B6F4367E8CA123 |
| retl | % | *44AB89E92CDF5A148EC5A8BCE2BBEF1E51AAC48D |
| sre | % | *66CC8D8F94978869E17ABDA6FD2E1A5D817E619E |
| hdm | % | *14533888C6CA3952B3957903FF7E69469C7E3A2B |
+-------------+---------------+-------------------------------------------+

设置

  • 配置文件 my.cnf
1
2
[mysqld]
skip-name-resolve
  • 日志警告
1
2
3
4
5
# skip_name_resolve = OFF
[Warning] IP address '10.163.25.68' could not be resolved: Name or service not known

# skip_name_resolve = ON
[Warning] 'user' entry 'mysql.session@localhost' ignored in --skip-name-resolve mode