程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 數據庫知識 >> MYSQL數據庫 >> MySQL綜合教程 >> 處理長途銜接mysql很慢的辦法(mysql_connect 翻開銜接慢)

處理長途銜接mysql很慢的辦法(mysql_connect 翻開銜接慢)

編輯:MySQL綜合教程

處理長途銜接mysql很慢的辦法(mysql_connect 翻開銜接慢)。本站提示廣大學習愛好者:(處理長途銜接mysql很慢的辦法(mysql_connect 翻開銜接慢))文章只能為提供參考,不一定能成為您想要的結果。以下是處理長途銜接mysql很慢的辦法(mysql_connect 翻開銜接慢)正文


在停止 ping和route後發明收集通訊都是正常的,並且在mysql機械長進行當地銜接發明是很快的,所以收集成績根本上被消除了。之前也碰到過一次如許的成績,可後來就不知怎樣忽然好了,此次又遭受如許的成績,所以想看看是否是mysql的設置裝備擺設成績。在查詢mysql相干文檔和收集搜刮後,發明了一個設置裝備擺設仿佛可以處理如許的成績,就是在mysql的設置裝備擺設文件中增長以下設置裝備擺設參數:

[mysqld]
skip-name-resolve

      在linux下設置裝備擺設文件是/etc/my.cnf,在windows下設置裝備擺設文件是mysql裝置目次下的my.ini文件。留意該設置裝備擺設是加在 [mysqld]上面,在更改設置裝備擺設並保留後,然後重啟mysql並長途銜接測試,一切恢復如初。該參數的官方說明信息以下:

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主機查詢DNS很慢或是有許多客戶端主機時會招致銜接很慢,因為我們的開辟機械是不克不及夠銜接外網的,所以DNS解析是弗成能完成的,從而也就明確了為何銜接那末慢了。同時,請留意在增長該設置裝備擺設參數後,mysql的受權表中的host字段就不克不及夠應用域名而只可以或許應用 ip地址了,由於這是制止了域名解析的成果。

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved