有次同事提出開發使用的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 主站蜘蛛池模板: 遂溪县| 保康县| 海淀区| 五原县| 宁河县| 漾濞| 黄石市| 陵水| 阿鲁科尔沁旗| 昌图县| 扶风县| 定襄县| 积石山| 满洲里市| 丽水市| 西城区| 喜德县| 休宁县| 安陆市| 雷山县| 东宁县| 江门市| 海兴县| 罗源县| 东方市| 荃湾区| 高密市| 得荣县| 南郑县| 名山县| 勃利县| 双柏县| 三台县| 洪雅县| 磴口县| 本溪市| 榆树市| 昌吉市| 神木县| 连州市| 咸宁市|