連接MySql速度慢的解決方法(skip-name-resolve)
最近在Linux服務(wù)器上安裝MySql5后,本地使用客戶端連MySql速度超慢,本地程序連接也超慢。
解決方法:在配置文件my.cnf的[mysqld]下加入skip-name-resolve。
原因是默認(rèn)安裝的MySql開啟了DNS的反向解析。如果禁用的話就不能在MySQL的授權(quán)表中使用主機名了而只能用ip格式。
附: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 lookup 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.
或者h(yuǎn)ost中添加
192.168.1.21 N-21
相關(guān)文章
Mysql auto_increment 重新計數(shù)(讓id從1開始)
當(dāng)清空一個表的時候,重新插入數(shù)據(jù),發(fā)現(xiàn)auto_increment屬性的字段計數(shù)不是從1開始的時候,可以使用以下命令2012-12-12
使用MySQL Slow Log來解決MySQL CPU占用高的問題
在Linux VPS系統(tǒng)上有時候會發(fā)現(xiàn)MySQL占用CPU高,導(dǎo)致系統(tǒng)的負(fù)載比較高。這種情況很可能是某個SQL語句執(zhí)行的時間太長導(dǎo)致的。優(yōu)化一下這個SQL語句或者優(yōu)化一下這個SQL引用的某個表的索引一般能解決問題2013-03-03
php連接不上mysql但mysql命令行操作正常的解決方法
這篇文章主要介紹了php連接不上mysql但mysql命令行操作正常的解決方法,需要的朋友可以參考下2014-04-04
MySQL中(JOIN/ORDER BY)語句的查詢過程及優(yōu)化方法
sql語句性能達(dá)不到你的要求,執(zhí)行效率讓你忍無可忍,一般會造成很多影響。那么我們?nèi)绾谓鉀Q這些問題呢,下面由小編來和大家簡單講下2019-05-05
解決mysql 1040錯誤Too many connections的方法
因為你的mysql安裝目錄下的my.ini中設(shè)定的并發(fā)連接數(shù)太少或者系統(tǒng)繁忙導(dǎo)致連接數(shù)被占滿2012-09-09
Mysql中STR_TO_DATE函數(shù)使用(字符串轉(zhuǎn)為日期/時間值)
這篇文章主要給大家介紹了關(guān)于Mysql中STR_TO_DATE函數(shù)使用的相關(guān)資料,STR_TO_DATE函數(shù)的主要功能是字符串轉(zhuǎn)為日期/時間值,文中通過示例代碼介紹的非常詳細(xì),需要的朋友可以參考下2022-09-09

