解決遠(yuǎn)程連接mysql很慢的方法(mysql_connect 打開連接慢)
[mysqld]
skip-name-resolve
在linux下配置文件是/etc/my.cnf,在windows下配置文件是mysql安裝目錄下的my.ini文件。注意該配置是加在 [mysqld]下面,在更改配置并保存后,然后重啟mysql并遠(yuǎn)程連接測試,一切恢復(fù)如初。該參數(shù)的官方解釋信息如下:
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主機(jī)查詢DNS很慢或是有很多客戶端主機(jī)時(shí)會(huì)導(dǎo)致連接很慢,由于我們的開發(fā)機(jī)器是不能夠連接外網(wǎng)的,所以DNS解析是不可能完成的,從而也就明白了為什么連接那么慢了。同時(shí),請(qǐng)注意在增加該配置參數(shù)后,mysql的授權(quán)表中的host字段就不能夠使用域名而只能夠使用 ip地址了,因?yàn)檫@是禁止了域名解析的結(jié)果。
- MySQL數(shù)據(jù)庫遠(yuǎn)程連接開啟方法
- MySQL遠(yuǎn)程連接丟失問題解決方法(Lost connection to MySQL server)
- 遠(yuǎn)程連接mysql 授權(quán)方法詳解
- Linux系統(tǒng)下實(shí)現(xiàn)遠(yuǎn)程連接MySQL數(shù)據(jù)庫的方法教程
- 配置mysql允許遠(yuǎn)程連接的方法
- MySQL遠(yuǎn)程連接不上的解決方法
- mysql 遠(yuǎn)程連接數(shù)據(jù)庫的方法集合
- MYSQL不能從遠(yuǎn)程連接的一個(gè)解決方法(s not allowed to connect to this MySQL server)
- 解決MySQL無法遠(yuǎn)程連接的方法
- MySql8設(shè)置遠(yuǎn)程連接的實(shí)戰(zhàn)記錄
相關(guān)文章
mysql SELECT語句去除某個(gè)字段的重復(fù)信息
mysql SELECT語句去除某個(gè)字段的重復(fù)信息,需要的朋友可以收藏下。2010-04-04
Mysql存在則修改不存在則新增的兩種實(shí)現(xiàn)方法實(shí)例
mysql語法支持如果數(shù)據(jù)存在則更新,不存在則插入,下面這篇文章主要給大家介紹了關(guān)于Mysql存在則修改不存在則新增的兩種實(shí)現(xiàn)方法,文中通過實(shí)例代碼介紹的非常詳細(xì),需要的朋友可以參考下2022-09-09
MySQL?bit類型增加索引后查詢結(jié)果不正確案例解析
這篇文章主要介紹了MySQL?bit類型增加索引后查詢結(jié)果不正確案例淺析,我們先創(chuàng)建表student_attend,初始化一些數(shù)據(jù),這篇文章的測試環(huán)境為MySQL 8.0.35社區(qū)版,具體內(nèi)容介紹跟隨小編一起學(xué)習(xí)吧2024-06-06
解決mysql @@sql_mode問題---only_full_group_by
這篇文章主要介紹了解決mysql @@sql_mode問題---only_full_group_by,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2024-09-09
MYSQL根據(jù)分組獲取組內(nèi)多條數(shù)據(jù)中符合條件的一條(實(shí)例詳解)
這篇文章主要介紹了MYSQL根據(jù)分組獲取組內(nèi)多條數(shù)據(jù)中符合條件的一條,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2023-06-06

