mysql服务器出现问题,ssh连上去,执行Show Processlist;命令,发现一堆的用户名是unauthenticated user的用户在连接。
开工,对mysql优化。
首先,查看show processlist运行概况
复制代码 代码示例:
mysql> show processlist;
+--------+----------------------+----------------------+----------+---------+------+-------+------------------+
| Id | User | Host | db | Command | Time | State | Info |
+--------+----------------------+----------------------+----------+---------+------+-------+------------------+
| 317953 | root | localhost | NULL | Query | 0 | NULL | show processlist |
| 318367 | unauthenticated user | 220.181.6.184:50295 | NULL | Connect | NULL | login | NULL |
| 318371 | unauthenticated user | 220.181.6.184:50296 | NULL | Connect | NULL | login | NULL |
| 318383 | unauthenticated user | 220.181.6.184:50299 | NULL | Connect | NULL | login | NULL |
| 318387 | unauthenticated user | 220.181.6.184:50301 | NULL | Connect | NULL | login | NULL |
| 318391 | unauthenticated user | 220.181.6.184:50303 | NULL | Connect | NULL | login | NULL |
| 318392 | unauthenticated user | 220.181.6.184:50304 | NULL | Connect | NULL | login | NULL |
| 318395 | unauthenticated user | 220.181.6.184:50305 | NULL | Connect | NULL | login | NULL |
| 318404 | root | localhost | blogguy.cn | Sleep | 1 | | NULL |
| 318409 | unauthenticated user | 220.181.6.184:50309 | NULL | Connect | NULL | login | NULL |
+--------+----------------------+----------------------+----------+---------+------+-------+------------------+
10 rows in set (0.00 sec)
看到大量unauthenticated user信息。
这是由mysql原始特性决定的:
mysql在接到连接请求时,如果收到的连接请求是IP地址的话,mysql会尝试由ip地址到DNS的反向解析。
解决办法:
1、在my.cnf中修改,[mysqld] 行下添加 --skip-name-resolve,这是公开的优化方式
配置脚本:
复制代码 代码示例:
[mysqld]
datadir=/var/lib/mysql
#socket=/var/lib/mysql/mysql.sock
socket=/tmp/mysql.sock
# Default to using old password format for compatibility with mysql 3.x
# clients (those using the mysqlclient10 compatibility package).
old_passwords=1
max_allowed_packet=50M
wait_timeout=2880000
interactive_timeout = 2880000
max_connections=2000
skip-name-resolve
[mysql.server]
user=mysql
#basedir=/var/lib
basedir=/usr/local/blogguy.cn/mysql
[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
如果配置文件中有set-variable 参数,后面可以用--skip-name-resolve的方式。
2、修改/etc/hosts文件,把相应的主机名,ip等信息写进hosts文件中。
重启mysql,应该没有那么多unauthenticated user了。