使用键盘快捷方式停止MySQL查询

时间:2016-07-13 10:33:08

标签: mysql mariadb

有没有办法可以用一些键盘快捷键来停止/终止正在运行的SQL查询?

我正在使用MariaDB。

1 个答案:

答案 0 :(得分:0)

以下是[ctrl] -C

的示例

示例[ctrl] -C

MariaDB [yourschema]> select sleep(999);
^CCtrl-C -- query killed. Continuing normally.
+------------+
| sleep(999) |
+------------+
+------------+
1 row in set (2.12 sec)

MariaDB [yourschema]>

示例KILL

窗口1

MariaDB [yourschema]> select sleep(999);

窗口2

MariaDB [(none)]> show processlist;
+--------+-----------------+-----------------+------------+---------+---------+-----------------------------+-------------------+----------+
| Id     | User            | Host            | db         | Command | Time    | State                       | Info              | Progress |
+--------+-----------------+-----------------+------------+---------+---------+-----------------------------+-------------------+----------+
|     34 | event_scheduler | localhost       | NULL       | Daemon  | 1340348 | Waiting for next activation | NULL              |    0.000 |
|  43607 | root            | localhost:65119 | yourSchema | Sleep   |      20 |                             | NULL              |    0.000 |
|  43609 | root            | localhost:65120 | NULL       | Sleep   |      58 |                             | NULL              |    0.000 |
|  80450 | root            | localhost:51083 | yourSchema | Sleep   |      68 |                             | NULL              |    0.000 |
|  80452 | root            | localhost:51084 | NULL       | Sleep   |      45 |                             | NULL              |    0.000 |
|  80545 | root            | localhost:51184 | yourSchema | Sleep   |       3 |                             | NULL              |    0.000 |
|  80546 | root            | localhost:51185 | NULL       | Sleep   |       3 |                             | NULL              |    0.000 |
| 129783 | root            | localhost       | yourschema | Query   |       9 | User sleep                  | select sleep(999) |    0.000 |
| 129809 | root            | localhost       | NULL       | Query   |       0 | init                        | show processlist  |    0.000 |
+--------+-----------------+-----------------+------------+---------+---------+-----------------------------+-------------------+----------+
9 rows in set (0.00 sec)

MariaDB [(none)]> kill 129783;
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]>

窗口1

ERROR 2013 (HY000): Lost connection to MySQL server during query
MariaDB [yourschema]>