I connect to mysql
from my Linux shell. Every now and then I run a SELECT
query that is too big. It prints and prints and I already know this is no
Just to add
KILL QUERY **Id**
where Id is connection id from show processlist
is more preferable if you are do not want to kill the connection usually when running from some application.
For more details you can read mysql doc here
If you have mysqladmin
available, you may get the list of queries with:
> mysqladmin -uUSERNAME -pPASSWORD pr
+-----+------+-----------------+--------+---------+------+--------------+------------------+
| Id | User | Host | db | Command | Time | State | Info |
+-----+------+-----------------+--------+---------+------+--------------+------------------+
| 137 | beet | localhost:53535 | people | Query | 292 | Sending data | DELETE FROM |
| 145 | root | localhost:55745 | | Query | 0 | | show processlist |
+-----+------+-----------------+--------+---------+------+--------------+------------------+
Then you may stop the mysql process that is hosting the long running query:
> mysqladmin -uUSERNAME -pPASSWORD kill 137
You need to run following command to kill the process.
> show processlist;
> kill query processId;
Query parameter specifies that we need to kill query command process.
The syntax for kill process as follows
KILL [CONNECTION | QUERY] processlist_id
Please refer this link for more information.
mysql>show processlist;
mysql> kill "number from first col";
Use mysqladmin
to kill the runaway query:
Run the following commands:
mysqladmin -uusername -ppassword pr
Then note down the process id.
mysqladmin -uusername -ppassword kill pid
The runaway query should no longer be consuming resources.
Connect to mysql
mysql -uusername -p -hhostname
show full processlist:
mysql> show full processlist;
+---------+--------+-------------------+---------+---------+------+-------+------------------+
| Id | User | Host | db | Command | Time | State | Info |
+---------+--------+-------------------+---------+---------+------+-------+------------------+
| 9255451 | logreg | dmin001.ops:37651 | logdata | Query | 0 | NULL | show processlist |
+---------+--------+-------------------+---------+---------+------+-------+------------------+
Kill the specific query. Here id=9255451
mysql> kill 9255451;
If you get permission denied, try this SQL:
CALL mysql.rds_kill(9255451)