日期:2014-05-16  浏览次数:20746 次

mysql远程连接突然变慢

今天突然数据库没法访问了,于是登录到服务器上,远程登录数据库,发现不是无法访问,而是特别慢,而且从local访问没有这个问题。

?

于是查看mysql里的进程,发现很多这种进程:

??????????????????? | NULL???????????? |
| 182 | unauthenticated user | 192.168.1.101:58804?? | NULL??????????????? | Connect???? | NULL | login????????????????????????????????????????????????????????? | NULL???????????? |
| 183 | unauthenticated user | 192.168.1.101:58806?? | NULL??????????????? | Connect???? | NULL | login????????????????????????????????????????????????????????? | NULL???????????? |
| 184 | unauthenticated user | 192.168.1.101:58807?? | NULL??????????????? | Connect???? | NULL | login????????????????????????????????????????????????????????? | NULL???????????? |
| 185 | unauthenticated user | 192.168.1.101:58808?? | NULL??????????????? | Connect???? | NULL | login????????????????????????????????????????????????????????? | NULL???????????? |
| 186 | unauthenticated user | 192.168.1.101:58811?? | NULL??????????????? | Connect???? | NULL | login????????????????????????????????????????????????????????? | NULL???????????? |
| 187 | aloha??????????????? | localhost???????????? | NULL??????????????? | Query?????? |??? 0 | NULL?????????????????????????????????????????????????????????? | show processlist |
| 188 | unauthenticated user | 192.168.1.101:58814?? | NULL??????????????? | Connect???? | NULL | login

?

?

goolge了一下,发现这属于官方一个系统上的特殊设定,就把他当成mysql的一个bug
不管链接的的方式是经过 hosts 或是 IP 的模式,他都会对 DNS 做反查
mysqld 会尝试去反查 IP -> dns ,由于反查解析过慢,就会无法应付过量的查询。

?

解决办法:

1 /usr/local/mysql/bin/mysqld_safe --skip-name-resolve --user=mysql&

加 --skip-name-resolve 这么一个参数就可以,关闭mysql的dns反查功能。

2 编辑/etc/my.cnf

在[mysqld]段中加入

skip-name-resolve

重启mysql

?

1 楼 ezwuhai 2012-05-16  
感谢楼主分享!