日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 运维知识 > 数据库 >内容正文

数据库

解决远程连接mysql很慢的问题(mysql_connect 打开连接慢)

發(fā)布時間:2025/7/14 数据库 27 豆豆
生活随笔 收集整理的這篇文章主要介紹了 解决远程连接mysql很慢的问题(mysql_connect 打开连接慢) 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
有次同事提出開發(fā)使用的mysql數(shù)據(jù)庫連接很慢,因為我們的mysql開發(fā)數(shù)據(jù)庫是單獨一臺機器部署的,所以認(rèn)為可能是網(wǎng)絡(luò)連接問題導(dǎo)致的。在進行 ping和route后發(fā)現(xiàn)網(wǎng)絡(luò)通信都是正常的,而且在mysql機器上進行本地連接發(fā)現(xiàn)是很快的,所以網(wǎng)絡(luò)問題基本上被排除了。以前也遇到過一次這樣的 問題,可后來就不知怎么突然好了,這次又遭遇這樣的問題,所以想看看是不是mysql的配置問題。在查詢mysql相關(guān)文檔和網(wǎng)絡(luò)搜索后,發(fā)現(xiàn)了一個配置 似乎可以解決這樣的問題,就是在mysql的配置文件中增加如下配置參數(shù):

[mysqld]

skip-name-resolve

?? ? ?在linux下配置文件是/etc/my.cnf,在windows下配置文件是mysql安裝目錄下的my.ini文件。注意該配置是加在 [mysqld]下面,在更改配置并保存后,然后重啟mysql并遠(yuǎn)程連接測試,一切恢復(fù)如初。該參數(shù)的官方解釋信息如下:(http://www.my400800.cn)

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.

?? ? ?根據(jù)文檔說明,如果你的mysql主機查詢DNS很慢或是有很多客戶端主機時會導(dǎo)致連接很慢,由于我們的開發(fā)機器是不能夠連接外網(wǎng)的,所以DNS解析是 不可能完成的,從而也就明白了為什么連接那么慢了。同時,請注意在增加該配置參數(shù)后,mysql的授權(quán)表中的host字段就不能夠使用域名而只能夠使用 ip地址了,因為這是禁止了域名解析的結(jié)果。

轉(zhuǎn)載于:https://www.cnblogs.com/jishu/archive/2011/06/29/2093043.html

總結(jié)

以上是生活随笔為你收集整理的解决远程连接mysql很慢的问题(mysql_connect 打开连接慢)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。