国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 數據庫 > MySQL > 正文

MySQL數據庫遠程連接很慢的解決方案

2024-07-24 12:53:07
字體:
來源:轉載
供稿:網友

有次同事提出開發使用的MySQL數據庫連接很慢,因為我們的MySQL開發數據庫是單獨一臺機器部署的,所以認為可能是網絡連接問題導致的。

在進行 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地址了 ,因為這是禁止了域名解析的結果。

您可能感興趣的文章:

MySQL數據庫遠程連接開啟方法遠程連接mysql 授權方法詳解MySQL遠程連接丟失問題解決方法(Lost connection to MySQL server)mysql 遠程連接數據庫的方法集合配置mysql允許遠程連接的方法解決遠程連接mysql很慢的方法(mysql_connect 打開連接慢)navicat無法遠程連接mysql的解決方法MYSQL不能從遠程連接的一個解決方法(s not allowed to connect to this MySQL server)PHP遠程連接MYSQL數據庫非常慢的解決方法詳解遠程連接Mysql數據庫的問題(ERROR 2003 (HY000))遠程連接mysql數據庫注意事項記錄(遠程連接慢skip-name-resolve)
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 金山区| 肇州县| 上杭县| 新建县| 象州县| 沂水县| 水城县| 潜山县| 青神县| 修水县| 阿拉尔市| 大同市| 长治市| 阿克| 明光市| 昌邑市| 如东县| 工布江达县| 古蔺县| 石门县| 唐海县| 富裕县| 林口县| 迁西县| 韶山市| 南丹县| 汽车| 井陉县| 大连市| 阳高县| 酉阳| 图木舒克市| 大洼县| 华池县| 五华县| 伊川县| 柳河县| 柳江县| 信宜市| 旬阳县| 江油市|