Linux Ask!

Linux Ask! is a Q & A web site specific for Linux related questions. Questions are collected, answered and audited by experienced Linux users.

How to check and kill long running MySQL query

Answer:

1. Get into the MySQL shell, type 'SHOW PROCESSLIST' to see which query is blocking

mysql> SHOW PROCESSLIST;

2. It will print out all the current executing queries, and you will find the thread Id.

+-----+-------------+--------------------+-------+---------+-------+

| Id | User  | Host            | db   | Command | Time| State     | Info                                                                                           

+-----+-------------+--------------------+-------+---------+-------+-
| 3928 |root  |192.168.1.5:59202 |db1 |Query    | 84   | Locked  |

select * from table1 where name like '%test%' 

3. Remember this Id, to kill it, use the "KILL" command

mysql> KILL 3928;

Query OK, 0 rows affected (0.05 sec)

  1. Vertical (\G) output of query result in MySQL client
  2. Reset MySQL root password
  3. Explain query execution plan in MySQL
  4. Disable Query Cache at runtime when querying MySQL database
  5. How to limit query results scrolling off the screen

Leave a Reply

(required)

(required)

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>