Tuesday, July 15, 2014

Purging MySQL active DB connections

In some cases when you are trying to truncate a table, there could be active DB connections that could prevent the query from executing quickly. In order to purge the active DB connections. Here is an example from Percona folks

mysql> select concat('KILL ',id,';') from information_schema.processlist where user='root';
+------------------------+
| concat('KILL ',id,';') |
+------------------------+
| KILL 3101;             |
| KILL 2946;             |
+------------------------+
2 rows in set (0.00 sec)
mysql> select concat('KILL ',id,';') from information_schema.processlist where user='root' into outfile '/tmp/a.txt';
Query OK, 2 rows affected (0.00 sec)
mysql> source /tmp/a.txt;
Query OK, 0 rows affected (0.00 sec)

No comments:

Post a Comment