《Mysql入門(mén)解決遠(yuǎn)程連接mysql很慢的方法(mysql_connect 打開(kāi)連接慢)》要點(diǎn):
本文介紹了Mysql入門(mén)解決遠(yuǎn)程連接mysql很慢的方法(mysql_connect 打開(kāi)連接慢),希望對(duì)您有用。如果有疑問(wèn),可以聯(lián)系我們。
MYSQL實(shí)例[mysqld]
skip-name-resolve
MYSQL實(shí)例?? ? ?在linux下配置文件是/etc/my.cnf,在windows下配置文件是mysql安裝目錄下的my.ini文件.注意該配置是加在 [mysqld]下面,在更改配置并保存后,然后重啟mysql并遠(yuǎn)程連接測(cè)試,一切恢復(fù)如初.該參數(shù)的官方解釋信息如下:
How MySQL uses DNS
MYSQL實(shí)例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.
MYSQL實(shí)例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.
MYSQL實(shí)例You can disable DNS host lookup by starting mysqld with Cskip-name-resolve. In this case you can however only use IP names in the MySQL privilege tables.
MYSQL實(shí)例If you have a very slow DNS and many hosts, you can get more performance by either disabling DNS lookop with Cskip-name-resolve or by increasing the HOST_CACHE_SIZE define (default: 128) and recompile mysqld.
MYSQL實(shí)例You can disable the hostname cache with Cskip-host-cache. You can clear the hostname cache with FLUSH HOSTS or mysqladmin flush-hosts.
MYSQL實(shí)例If you don't want to allow connections over TCP/IP, you can do this by starting mysqld with Cskip-networking.
MYSQL實(shí)例?? ? ?根據(jù)文檔說(shuō)明,如果你的mysql主機(jī)查詢DNS很慢或是有很多客戶端主機(jī)時(shí)會(huì)導(dǎo)致連接很慢,由于我們的開(kāi)發(fā)機(jī)器是不能夠連接外網(wǎng)的,所以DNS解析是不可能完成的,從而也就明白了為什么連接那么慢了.同時(shí),請(qǐng)注意在增加該配置參數(shù)后,mysql的授權(quán)表中的host字段就不能夠使用域名而只能夠使用 ip地址了,因?yàn)檫@是禁止了域名解析的結(jié)果.
轉(zhuǎn)載請(qǐng)注明本頁(yè)網(wǎng)址:
http://www.fzlkiss.com/jiaocheng/2060.html