MySQL的error log 出现大量的 DNS反解析错误。

DNS解析是指,将 域名解析成ip地址;

DNS反解析是指,将IP地址反解析成域名;

Version: '5.5.40-log'  socket: '/tmp/mysql.sock'  port:   MySQL Community Server (GPL)
:: [Warning] IP address 'xxx.xxx.xx.xxx' could not be resolved: Name or service not known
:: [Warning] IP address 'xxx.xxx.xx.xxx' could not be resolved: Name or service not known
:: [Warning] IP address 'xxx.xxx.xx.xxx' could not be resolved: Name or service not known
:: [Warning] IP address 'xxx.xxx.xx.xxx' could not be resolved: Name or service not known
:: [Warning] IP address 'xxx.xxx.xx.xxx' could not be resolved: Name or service not known
:: [Warning] IP address 'xxx.xxx.xx.xxx' could not be resolved: Name or service not known
:: [Warning] IP address 'xxx.xxx.xx.xxx' could not be resolved: Name or service not known
:: [Warning] IP address 'xxx.xxx.xx.xxx' could not be resolved: Name or service not known
1 :: [Warning] IP address 'xxx.xxx.xx.xxx' could not be resolved: Temporary failure in name resolution
:: [Warning] IP address 'xxx.xxx.xx.xxx' could not be resolved: Temporary failure in name resolution
:: [Warning] IP address 'xxx.xxx.xx.xxx' has been resolved to the host name 'xxx.xxx.xx.xxx.broadxxxxx.com.cn', which resembles IPv4-address itself.
:: [Warning] IP address 'xxx.xxx.xx.xxx' could not be resolved: Name or service not known
:: [Warning] IP address 'xxx.xxx.xx.xxx' could not be resolved: Name or service not known
:: [Warning] IP address 'xxx.xxx.xx.xxx' could not be resolved: Name or service not known

出现该错误的原因:

MySQL 数据库服务器没有配置 /etc/hosts,也没有DNS服务,导致mysqld线程解析IP对应的主机名时,解析失败。

解决方法:

使用--skip-name-resolve 参数禁用DNS的主机名解析功能,禁用该功能后,在MySQL授权表里面,你只能使用IP地址。

所以我们修改MySQL的my.cnf中的参数:

[mysqld]
skip_host_cache
skip-name-resolve=
could not be resolved: Temporary failure in name resolution 的警告,可以使用 skip_host_cache 来搞定;
而 could not be resolved: Name or service not known 的警告,可以通过 skip_name_resolve=1 来搞定。禁止了域名解析,显然就不会出该警告了。

注意:skip_host_cache=1 会报错。直接 skip_host_cache 或者 skip-host-cache 就行了。

修改之后,需要重启。

注意:mysql中的权限表,就不能使用域名了,必须使用IP地址来设置。

msyql文档:

--skip-name-resolve

Do not resolve host names when checking client connections. Use only IP addresses. If you use this option, all Host column values 
in the grant tables must be IP addresses or localhost. See Section 8.12.6.2, “DNS Lookup Optimization and the Host Cache”. Depending on the network configuration of your system and the Host values for your accounts, clients may need to connect using an
explicit --host option, such as --host=localhost, --host=127.0.0.1, or --host=::. An attempt to connect to the host 127.0.0.1 normally resolves to the localhost account. However, this fails if the server is run
with the --skip-name-resolve option, so make sure that an account exists that can accept a connection. For example, to be able to connect as root using --host=127.0.0.1 or --host=::, create these accounts: CREATE USER 'root'@'127.0.0.1' IDENTIFIED BY 'root-password';
CREATE USER 'root'@'::1' IDENTIFIED BY 'root-password';
--skip-host-cache

Disable use of the internal host cache for faster name-to-IP resolution. In this case, the server performs a DNS lookup every time 
a client connects. See Section 8.12.6.2, “DNS Lookup Optimization and the Host Cache”. Use of --skip-host-cache is similar to setting the host_cache_size system variable to , but host_cache_size is more flexible
because it can also be used to resize, enable, or disable the host cache at runtime, not just at server startup. If you start the server with --skip-host-cache, that does not prevent changes to the value of host_cache_size, but such changes
have no effect and the cache is not re-enabled even if host_cache_size is set larger than .

其实,按照上面的介绍,如果我们启用了 skip-name-resolve=1, 那么因为禁止了 ip 和 hostname 之间的解析,那么就没有必要启用 skip-host-cache 了。启用的话,可能会减少一点点内存的占用吧?

--------------------------------分割线---------------------------------------

Mysql域名解析(转自:http://www.jb51.net/article/70893.htm):

当一个新的客户端尝试跟mysqld创建连接时,mysqld产生一个新线程来处理这个请求。新线程会先检查请求建立连接的主机名是否在Mysql的主机名缓冲中,如果不在,线程会尝试去解析请求连接的主机名。

解析的逻辑如下:

a. Mysql线程通过gethostbyaddr()把获取的IP地址解析成主机名,然后通过gethostbyname()把获取的主机名解析成IP地址,保障主机名和IP地址对应关系的准确

b. 如果操作系统支持使用安全进程的gethostbyaddr_r()和gethostbyname_r() 调用,Mysqld线程可以用它俩来优化主机名解析;

c. 如果操作系统不支持安全线程调用,Mysqld进程先做一个互斥锁,然后调用gethostbyaddr()和gethostbyname()解析主机 名。此时,在第一个进程释放掉主机名缓冲池的主机名之前,其它进程无法再次解析这个主机名; <-------MySQL手册里面在此处说的host name ,意思应该是指同一个IP地址和对应的第一个主机名关系。

在启动mysqld进程是,可以使用 --skip-name-resolve 参数禁用DNS的主机名解析功能,禁用该功能后,在MySQL授权表里面,你只能使用IP地址。

如果你所处环境的DNS非常慢 或者 有很多主机, 你可以通过禁用DNS解析功能--skip-name-resolve 或者 提高 HOST_CACHE_SIZE大小 来提升数据库的响应效率。

禁用主机名缓冲的发方法: 使用--skip-host-cache 参数; 刷新主机名缓冲区: 执行 flush hosts 或者执行mysqladmin flush-hosts;

=============================

启用 skip_name_resolve=1 之后,可能会有新的Warining:

[Warning] 'proxies_priv' entry '@ root@localhost.localdomain' ignored in --skip-name-resolve mode.

解决方法,删除表 mysq.proxies_priv 中值为 localhost.localdomain 的行

参见:http://blog.itpub.net/14184018/viewspace-1061224/

MySQL [Warning]: IP address 'xxxx' could not be resolved: Name or service not known的更多相关文章

  1. IP address could not be resolved: Name or service not known

    [root@test ~]# /usr/local/mysql/bin/mysqld2018-08-05T07:00:33.647509Z 0 [Warning] [MY-011070] [Serve ...

  2. IP address could not be resolved: Temporary failure in name resolution

    今早发现mysql日志中有非常多例如以下的警告: 140724 18:41:25 [Warning] IP address '172.16.18.217' could not be resolved: ...

  3. mysql could not be resolved: Name or service not known

    问题: mysql DNS反解:skip-name-resolve 错误日志有类似警告: 1.120119 16:26:04 [Warning] IP address '192.168.1.10' c ...

  4. ERROR 2003 (HY000): Can't connect to MySQL server on 'ip address' (111)的处理办法

    远程连接mysql数据库时可以使用以下指令 mysql -h 192.168.1.104 -u root -p 如果是初次安装mysql,需要将所有/etc/mysql/内的所有配置文件的bind-a ...

  5. ubuntu使用git的时:Warning: Permanently added the RSA host key for IP address '13.250.177.223' to the list of known hosts.

    1:问题现象: hlp@hlp:~/code/github_code/catch_imooc1$ git push origin master Warning: Permanently added t ...

  6. IP address '121.41.35.30' could not be resolved: Name or service not known解决方法

    IP address '121.41.35.30' could not be resolved: Name or service not known解决方法 添加如下 然后重启 即可解决<pre ...

  7. [转]How to convert IP address to country name

    本文转自:http://www.codeproject.com/Articles/28363/How-to-convert-IP-address-to-country-name   Download ...

  8. 错误RSA host key for [ip address] has changed and you have requested strict checking.

    @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ WARNING: REMOTE HOST IDENTIFICATION HAS ...

  9. 解决办法: RSA host key for [ip address] has changed and you have requested strict checking.

    在服务器重装后想要远程连接服务器,报错如下: @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @ WARNING: REMOTE ...

随机推荐

  1. Android版的菜谱客户端应用源码完整版

    Android版的菜谱客户端应用源码完整版,这个文章是从安卓教程网转载过来的,不是本人的原创,希望能够帮到大家的学习吧. <ignore_js_op> 152936qc7jdnv6vo0c ...

  2. JAVA多线程和并发基础面试问答(转载)

    JAVA多线程和并发基础面试问答 原文链接:http://ifeve.com/java-multi-threading-concurrency-interview-questions-with-ans ...

  3. Java程序,JDK的安装、环境的配置

    打开文件包,找到jdk-8u111-windows-x64  (64位)  双击打开安装界面 路径自行更改;(不可使用中文字段)新建一个文件夹放后面这个安装包 二.设置环境变量 右键我的电脑-属性-高 ...

  4. 算法:二分查找(python版)

    #!/usr/bin/env python #coding -*- utf:8 -*- #二分查找#时间复杂度O(logn)#一个时间常量O(1)将问题的规模缩小一半,则O(logn) import ...

  5. 自学H5第一天笔记

    1.web前端开发工程师 1.web前端开发工程师是做什么的 要与网站打交道 2.成为一名web前端开发工程师需要具备的条件 1.兴趣 2.敲代码 3.web前端开发需要学习什么 1.软件 浏览器:有 ...

  6. .Net中的并行编程-6.常用优化策略

                本文是.Net中的并行编程第六篇,今天就介绍一些我在实际项目中的一些常用优化策略.      一.避免线程之间共享数据 避免线程之间共享数据主要是因为锁的问题,无论什么粒度的锁 ...

  7. Code First :使用Entity. Framework编程(1) ----转发 收藏

    这个是在学习EF CodeFirst时发现的,对于初学者还是不错的.果断转发,方便自己以后查阅和学习. 对于学习Code First 这个教程讲解的还是很详细. 第一章:欢迎来到Code First ...

  8. Nivo Slider - 世界上最棒的 jQuery 图片轮播插件

    Nivo Slider 号称世界上最棒的图片轮播插件,有独立的 jQuery 插件和 WordPress 插件两个版本.目前下载量已经突破 1,800,000 次!jQuery 独立版本的插件主要有如 ...

  9. Immutable.js – JavaScript 不可变数据集合

    不可变数据是指一旦创建就不能被修改的数据,使得应用开发更简单,允许使用函数式编程技术,比如惰性评估.Immutable JS 提供一个惰性 Sequence,允许高效的队列方法链,类似 map 和 f ...

  10. [deviceone开发]-QQ分享、微信分享和新浪微博分享

    一.简介 该demo主要实现QQ分享.微信分享和新浪微博分享.(调试包请到论坛扫描对应二维码下载) 二.效果图 三.相关讨论 http://bbs.deviceone.net/forum.php?mo ...