Database Madness

From WTFwiki
Revision as of 10:20, 26 August 2010 by Jontow (talk | contribs) (add mysql kill-connections)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Killing User Connections

MySQL

To kill a user's connection from MySQL (ie. a PHP process, CLI client, etc), you need
to figure out the process id ("pid") of that connection, first. You can do this like so:

mysql> show processlist;
+---------+----------+-----------+------+---------+------+-------+------------------+
| Id      | User     | Host      | db   | Command | Time | State | Info             |
+---------+----------+-----------+------+---------+------+-------+------------------+
| 1177101 | root     | localhost | NULL | Query   |    0 | NULL  | show processlist | 
+---------+----------+-----------+------+---------+------+-------+------------------+
2 rows in set (0.01 sec)


In this example, there is one connection (mine, from the CLI). That is the one I'd like to
disconnect, so:

mysql> kill 1177101;
Query OK, 0 rows affected (0.00 sec)

mysql> show processlist;
ERROR 2006 (HY000): MySQL server has gone away
No connection. Trying to reconnect...
Connection id:    1177102
Current database: *** NONE ***


At this point, the connection has gone away, and your CLI client will reconnect automatically.