问题描述:
Windows2003下的MySQL服务器,本机连接到MySQL服务非常快,同一节点的Linuxecs,输入密码后要等好几秒钟才能连上。
客户端10.47.91.166
mysql服务器端10.160.27.175
内网Ping 正常,无丢包
解决过程:
先抓包分析一下:
发现服务器首先是要netbios协议进行名称和IP的解析查询,这个自然需要些时间。结合mysql的官方文档发现原因如下:
mysql 启动时默认不启用skip-name-resolve选项,导致其他主机连接数据库时,mysql会对其IP做DNS反向查询。
1、在my.ini或my.cnf文件的[mysqld]下加上skip-name-resolve
2、重启mysql
找了mysql 如何使用dns的官方说明
When a new thread connects tomysqld, mysqld will spawn a new thread to handle the request. This thread willfirst check if the hostname is in the hostname cache. If not the thread willcall gethostbyaddr_r() and gethostbyname_r() to resolve the hostname.
If the operating systemdoesn't support the above thread-safe calls, the thread will lock a mutex andcall gethostbyaddr() and gethostbyname() instead. Note that in this case noother thread can resolve other hostnames that is not in the hostname cacheuntil the first thread is ready.
You can disable DNS hostlookup by starting mysqld with –skip-name-resolve. In this case you can howeveronly use IP names in the MySQL privilege tables.
If you have a very slow DNSand many hosts, you can get more performance by either disabling DNS lookopwith –skip-name-resolve or by increasing the HOST_CACHE_SIZE define (default:128) and recompile mysqld.
You can disable the hostnamecache with –skip-host-cache. You can clear the hostname cache with FLUSH HOSTSor mysqladmin flush-hosts.
If you don't want to allowconnections over TCP/IP, you can do this by starting mysqld with–skip-networking.
当一个新的请求到达mysql服务时,mysql服务会派生一个子进程来处理这个请求的全部事宜。这个子进程首先会检查发来请求的主机名是否在缓存中,如果不存在则会进程DNS解析来查找主机名。
可以通过在mysqld标签下skip-name-resolve禁用DNS解析。注意:在mysql配置文件中加入skip-name-resolve选项 即禁止DNS解析后,mysql库中user表中的host字段不能使用域名。
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。