MySql使用skip-name-resolve解决外网链接客户端过慢问题
在腾讯云上面搭建的mysql使用开发的电脑上navicat进行访问时总是特别的慢,原来是Mysql会对请求的地址进行域名解析,开发的电脑并没有域名,所以会导致特别的慢,使用以下进行解决
[mysqld] skip-name-resolve skip-grant-tables
官方的解释
HowMySQL
usesDNSWhenanewthreadconnectstomysqld,mysqldwill
spawnanewthreadtohandletherequest.Thisthreadwillfirstcheck
ifthehostnameisinthehostnamecache.Ifnotthethreadwillcall
gethostbyaddr_r()andgethostbyname_r()toresolvethehostname.If
theoperatingsystemdoesn'tsupporttheabovethread-safecalls,the
threadwilllockamutexandcallgethostbyaddr()andgethostbyname()
instead.Notethatinthiscasenootherthreadcanresolveother
hostnamesthatisnotinthehostnamecacheuntilthefirstthreadis
ready.YoucandisableDNShostlookupbystartingmysqldwith
–skip-name-resolve.InthiscaseyoucanhoweveronlyuseIPnamesin
theMySQLprivilegetables.IfyouhaveaveryslowDNSandmany
hosts,youcangetmoreperformancebyeitherdisablingDNSlookop
with–skip-name-resolveorbyincreasingtheHOST_CACHE_SIZEdefine
(default:128)andrecompilemysqld.Youcandisablethehostname
cachewith–skip-host-cache.Youcanclearthehostnamecachewith
FLUSHHOSTSormysqladminflush-hosts.Ifyoudon'twanttoallow
connectionsoverTCP/IP,youcandothisbystartingmysqldwith
–skip-networking.
根据文档说明,如果你的mysql主机查询DNS很慢或是有很多客户端主机时会导致连接很慢,由于我们的开发机器是不能够连接外网的,所以DNS解析是不可能完成的,从而也就明白了为什么连接那么慢了。同时,请注意在增加该配置参数后,mysql的授权表中的host字段就不能够使用域名而只能够使用ip地址了,因为这是禁止了域名解析的结果。
总结
以上所述是小编给大家介绍的MySql使用skip-name-resolve解决外网链接客户端过慢问题,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对毛票票网站的支持!