遠程鏈接mysql速度慢的解決方法

 PHP遠程鏈接MYSQL速度慢,有時遠程鏈接到MYSQL用時4-20秒不等,本地鏈接MYSQL正常,出現這種問題的主要緣由是,默認安裝的MYSQL開啓了DNS的反向解析,在MY.INI(WINDOWS系統下)或MY.CNF(UNIX或LINUX系統下)文件的[mysqld]下加入skip-name-resolve這一句。鏈接mysql速度慢的解決方法.php

 
2臺服務器,一臺跑iis+php,一臺跑mysql,和以往同樣配置好環境,測試頁面一切OK
 
跑應用的時候發現php訪問mysql速度很慢,這種狀況在之前從未發現過,雖然2臺服務器並不是在同一網段中,可是ping數值基本上都在1,2ms之間,tcp鏈接應該不是問題關健,google之後找到答案,在my.ini文件的[mysqld]部分加入:skip-name-resolve,保存文件,重啓mysql,一切OK啦,速度象飛同樣了
 
新版本的mysql配置起來不象之前的那個傻瓜化了,這個問題折騰了我一上午的時間,晚上回來總算是解決了,嘿嘿,又學到一些東西。
 
Windows 2003下的MySQL 5服務器,本機鏈接到MySQL服務很是快,局域網內有兩臺Linux機器,有一臺鏈接很快,另一臺輸入密碼後要等好幾秒鐘才能連上。
 
解決辦法:
 
在MySQL服務器的配置中增長一個以下配置後速度飛快。
 
[mysqld]
skip-name-resolve
 
附錄:( 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.
 
PHP遠程鏈接MYSQL速度慢,有時遠程鏈接到MYSQL用時4-20秒不等,本地鏈接MYSQL正常,出現這種問題的主要緣由是,默認安裝的MYSQL開啓了DNS的反向解析,在MY.INI(WINDOWS系統下)或MY.CNF(UNIX或LINUX系統下)文件的[mysqld]下加入skip-name-resolve這一句。
 
MYSQL遠程鏈接速度慢的解決方法
在局域網內鏈接其餘機器的MYSQL,發現速度慢的很,不知道什麼緣由,總有幾秒的延遲.
 
後來在網上發現解決方法,my.ini裏面添加
 
[mysqld]
skip-name-resolve
skip-grant-tables
 
這樣速度就快了!
 
skip-name-resolve
 
選項就能禁用DNS解析,鏈接速度會快不少。不過,這樣的話就不能在MySQL的受權表中使用主機名了而只能用ip格式。
 
若使用–skip-grant-tables系統將對任何用戶的訪問不作任何訪問控制,但能夠用 mysqladmin flush-privileges或mysqladmin reload來開啓訪問控制;默認狀況是show databases語句對全部用戶開放,
 
若是mysql服務器沒有開遠程賬戶,就在my.ini裏面加上skip-grant-tables
相關文章
相關標籤/搜索