服务器上的MySQL出现了一个不算太陌生的错误“Too many connections”。平常碰到这个问题,我基本上是修改/etc/my.cnf的max_connections参数,然后重启数据库。但
是生产服务器上数据库又不能随便重启。
没办法,只好想办法手动去释放一些没用的连接。
登陆到MySQL的提示符下,数据show processlist这个命令,可以得到所以连接到这个服务器上的MySQL连接:
然后,你可以看到像上面这样的MySQL数据连接列表,而且每一个都会有一个进程ID号(在上表的第一列)。我们只要输入这样的命令:
其中1180421为你在进程列表里找到并且要杀掉的进程号.
是生产服务器上数据库又不能随便重启。
没办法,只好想办法手动去释放一些没用的连接。
登陆到MySQL的提示符下,数据show processlist这个命令,可以得到所以连接到这个服务器上的MySQL连接:
mysql> show processlist;
+---------+------+---------------------+---------+---------+------+-------+-------------------+
| Id | User | Host | db | Command | Time | State | Info |
+---------+------+---------------------+---------+---------+------+-------+-------------------+
| 1180421 | ur | 202.103.96.68:49754 | test1 | Sleep | 1 | | NULL |
| 1180427 | ur | 202.103.96.68:55079 | test2 | Sleep | 1 | | NULL |
| 1180429 | ur | 202.103.96.68:55187 | testdba | Sleep | 0 | | NULL |
| 1180431 | ur | 202.103.96.68:55704 | testdba | Sleep | 0 | | NULL |
| 1180437 | ur | 202.103.96.68:32825 | test1 | Sleep | 1 | | NULL |
| 1180469 | ur | 202.103.96.68:58073 | testdba | Sleep | 0 | | NULL |
| 1180472 | ur | 83.136.93.131:47613 | test2 | Sleep | 8 | | NULL |
| 1180475 | root | localhost | NULL | Query | 0 | NULL | show PROCESSLIST |
+---------+------+---------------------+---------+---------+------+-------+-------------------+
8 rows in set (0.00 sec)
mysql>
+---------+------+---------------------+---------+---------+------+-------+-------------------+
| Id | User | Host | db | Command | Time | State | Info |
+---------+------+---------------------+---------+---------+------+-------+-------------------+
| 1180421 | ur | 202.103.96.68:49754 | test1 | Sleep | 1 | | NULL |
| 1180427 | ur | 202.103.96.68:55079 | test2 | Sleep | 1 | | NULL |
| 1180429 | ur | 202.103.96.68:55187 | testdba | Sleep | 0 | | NULL |
| 1180431 | ur | 202.103.96.68:55704 | testdba | Sleep | 0 | | NULL |
| 1180437 | ur | 202.103.96.68:32825 | test1 | Sleep | 1 | | NULL |
| 1180469 | ur | 202.103.96.68:58073 | testdba | Sleep | 0 | | NULL |
| 1180472 | ur | 83.136.93.131:47613 | test2 | Sleep | 8 | | NULL |
| 1180475 | root | localhost | NULL | Query | 0 | NULL | show PROCESSLIST |
+---------+------+---------------------+---------+---------+------+-------+-------------------+
8 rows in set (0.00 sec)
mysql>
mysql> kill 1180421;
Query OK, 0 rows affected (0.00 sec)
mysql>
Query OK, 0 rows affected (0.00 sec)
mysql>
No comments:
Post a Comment