广告
返回顶部
首页 > 资讯 > 数据库 >mysql skip-name
  • 733
分享到

mysql skip-name

mysqlskip-name 2019-05-08 18:05:46 733人浏览 绘本
摘要

skip-name-resolve IP address "XX.XX.XX.XX" has been resolved to the host name "XX.XX.XX.XX.ro.ovo.sc", which re

mysql skip-name

skip-name-resolve IP address "XX.XX.XX.XX" has been resolved to the host name "XX.XX.XX.XX.ro.ovo.sc", which resembles IPv4-address itself.

 

Mysql连接很慢,登陆到服务器上查看mysql日志
IP address "XX.XX.XX.XX" has been resolved to the host name "XX.XX.XX.XX.ro.ovo.sc", which resembles IPv4-address itself.


原因是由于mysql对连接的客户端进行DNS反向解析。
有2种解决办法:
1,把client的ip写在mysql服务器的/etc/hosts文件里,随便给个名字就可以了。
2,在 my.cnf 中加入 –skip-name-resolve 。
对于第一种方法比较笨,也不实用,那么 skip-name-resolve 选项可以禁用dns解析,但是,这样不能在mysql的授权表中使用主机名了,只能使用IP。
我理解mysql是这样来处理客户端解析过程的,
1,当mysql的client连过来的时候,服务器会主动去查client的域名。
2,首先查找 /etc/hosts 文件,搜索域名和IP的对应关系。
3,如果hosts文件没有,则查找DNS设置,如果没有设置DNS服务器,会立刻返回失败,就相当于mysql设置了skip-name-resolve参数,如果设置了DNS服务器,就进行反向解析,直到timeout。



所谓反向解析是这样的:
mysql接收到连接请求后,获得的是客户端的ip,为了更好的匹配mysql.user里的权限记录(某些是用hostname定义的)。
如果mysql服务器设置了dns服务器,并且客户端ip在dns上并没有相应的hostname,那么这个过程很慢,导致连接等待。
 

添加skip-name-resolve以后就跳过着一个过程了。

官方的解释

How MySQL
uses DNS When a new thread connects to mysqld, mysqld will
spawn a new thread to handle the request. This thread will first check
if the hostname is in the hostname cache. If not the thread will call
gethostbyaddr_r() and gethostbyname_r() to resolve the hostname. If
the operating system doesn’t support the above thread-safe calls, the
thread will lock a mutex and call gethostbyaddr() and gethostbyname()
instead. Note that in this case no other thread can resolve other
hostnames that is not in the hostname cache until the first thread is
ready. You can disable DNS host lookup by starting mysqld with
–skip-name-resolve. In this case you can however only use IP names in
the MySQL privilege tables. If you have a very slow DNS and many
hosts, you can get more perfORMance by either disabling DNS lookop
with –skip-name-resolve or by increasing the HOST_CACHE_SIZE define
(default: 128) and recompile mysqld. You can disable the hostname
cache with –skip-host-cache. You can clear the hostname cache with
FLUSH HOSTS or mysqladmin flush-hosts. If you don’t want to allow
connections over tcp/IP, you can do this by starting mysqld with
–skip-networking.

注意:在增加该配置参数后,mysql的授权表中的host字段就不能够使用域名而只能够使用 ip地址了,因为这是禁止了域名解析的结果。

您可能感兴趣的文档:

--结束END--

本文标题: mysql skip-name

本文链接: https://www.lsjlt.com/news/5945.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
猜你喜欢
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作