有次同事提出開發使用的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 主站蜘蛛池模板: 淅川县| 德江县| 正宁县| 遂宁市| 荣成市| 贡嘎县| 淅川县| 英山县| 娱乐| 金乡县| 靖江市| 牟定县| 隆德县| 宜州市| 通城县| 大悟县| 普宁市| 额尔古纳市| 呼图壁县| 盐边县| 横峰县| 庆云县| 南通市| 六安市| 耒阳市| 波密县| 枣阳市| 鹤岗市| 江油市| 成安县| 巫山县| 吕梁市| 衡水市| 竹溪县| 雅江县| 彭阳县| 株洲县| 水城县| 塔河县| 华安县| 西宁市|