解决MySQL反解析错误could not be resolved: Name or service not known

mysql8 mysql · systemofdown · 于 2年前 发布 · 4175 次阅读

症状

错误日志有类似警告:

2022-09-30T22:06:54.574595Z 3547210 [Warning] [MY-010055] [Server] IP address '167.94.145.58' could not be resolved: Name or service not known
2022-09-30T23:09:54.824567Z 3547902 [Warning] [MY-010057] [Server] IP address '34.78.6.216' has been resolved to the host name '216.6.78.34.bc.googleusercontent.com', which resembles IPv4-address itself.
2022-10-01T00:03:56.392549Z 3549609 [Warning] [MY-010055] [Server] IP address '8.219.71.118' could not be resolved: Name or service not known
2022-10-01T00:35:57.319776Z 3550855 [Warning] [MY-010055] [Server] IP address '61.160.213.46' could not be resolved: Name or service not known
2022-10-01T01:08:59.061643Z 3553794 [Warning] [MY-010055] [Server] IP address '8.219.71.118' could not be resolved: Name or service not known

通过show processlist发现大量类似如下的连接:

|592|unauthenticated user|192.168.1.10:35320|NULL|Connect| |login|NULL|
|593|unauthenticated user|192.168.1.14:35321|NULL|Connect| |login|NULL|
|594|unauthenticated user|192.168.1.17:35322|NULL|Connect| |login|NULL|

解决办法

修改配置文件vim \etc\my.cnf添加并需要重启:

[mysqld] 
skip-name-resolve

skip-name-resolve 参数的作用:不再进行反解析(ip不反解成域名),这样可以加快数据库的反应时间。

⚠️ 注意: 修改后有可能链接不到数据库

如果开启该选项,则所有远程主机连接授权必须使用IP地址方式,否则MySQL将无法正常处理连接请求。

要确认 MySql 是否采用过主机名的授权, 在 mysql 中运行如下命令:

select user,host from mysql.user where host = 'localhost' ;

找到对应的用户授权记录, 需要修改一下将localhost替换为127.0.0.1

本文由 systemofdown 创作,采用 知识共享署名 3.0 中国大陆许可协议 进行许可。 可自由转载、引用,但需署名作者且注明文章出处。

共收到 0 条回复
没有找到数据。
添加回复 (需要登录)
需要 登录 后方可回复, 如果你还没有账号请点击这里 注册