1. 单数据库连接瓶颈,可以看到很多连接都sleep
mysql> show processlist;
+-----+-------------+--------------------+-------+---------+-------+----------------------------------+----------
| Id | User | Host | db | Command | Time| State | Info
+-----+-------------+--------------------+-------+---------+-------+----------------------------------+----------
|207|root |192.168.0.20:51718 |mytest | Sleep | 5 | | NULL
|208|root |192.168.0.20:51719 |mytest | Sleep | 5 | | NULL
设置wait_timeout的值,有效减少sleep进程
设置wait_timeout的方法有2个:
# vi /etc/my.cnf (在windows下是my.ini)
[mysqld]
wait_timeout=10
# /etc/init.d/mysql restart
这个方法设置后即使服务器以后重启,设置照样生效,不过这个方法会造成mysql服务重启,无论如何都应该尽可能避免;
下面看看在MySQL命令行里通过SET来设置:
mysql> set global wait_timeout=10;
mysql> show global variables like 'wait_timeout';
+----------------------------+-------+
| Variable_name | Value |
+----------------------------+-------+
| wait_timeout | 10 |
+----------------------------+-------+
这里一个容易把人搞蒙的地方是如果查询时使用的是show variables的话,会发现设置好像并没有生效,这是因为单纯使用show variables的话就等同于使用的是show session variables,查询的是会话变量,只有使用show global variables,查询的才是全局变量。
网络上很多人都抱怨说他们set global之后使用show variables查询没有发现改变,原因就在于混淆了会话变量和全局变量,如果仅仅想修改会话变量的话,可以使用类似set wait_timeout=10;或者set session wait_timeout=10;这样的语法。
这个方法只是临时性的,如果服务器重启后,wait_timeout的值又会变成28800。
2. MYSQL服务器出现大量unauthenticated user
| 364 | unauthenticated user | xxx.xxx.xxx.xxx:63249 | NULL | Connect | | login | NULL | | 365 | unauthenticated user | xxx.xxx.xxx.xxx:56768 | NULL | Connect | | login | NULL | | 366 | unauthenticated user | xxx.xxx.xxx.xxx:54127 | NULL | Connect | | login | NULL | | 367 | unauthenticated user | xxx.xxx.xxx.xxx:51060 | NULL | Connect | | login | NULL | |
[root@www king]# more /etc/my.cnf
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
skip-name-resolve
# Default to using old password format for compatibility with mysql 3.x
# clients (those using the mysqlclient10 compatibility package).
old_passwords=1
default-character-set = utf8
[mysql.server]
user=mysql
basedir=/var/lib
[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
[mysql]
default-character-set = utf8
#max_connections=1000
#skip-name-resolve
重启服务以后再mysql> show processlist;检查一下 你会发现那些unauthenticated user全部消失了。