开发者社区> 问答> 正文

为什么同一节点下windows的mysql比linux连接服务要快

问题描述:
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字段不能使用域名。

展开
收起
zhangmeng 2016-01-11 15:33:24 10296 0
0 条回答
写回答
取消 提交回答
问答排行榜
最热
最新

相关电子书

更多
Alibaba Cloud Linux 3 发布 立即下载
ECS系统指南之Linux系统诊断 立即下载
ECS运维指南 之 Linux系统诊断 立即下载