Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MySQL Session - Kill query to unlock table

Tags:

mysql

A query has locked a table in MySQL. How can the running query's session be killed to unlock the table?

I do not know to view the active sessions/processes in MySQL. How can I this via SSH?

like image 781
user1259132 Avatar asked Jul 17 '12 13:07

user1259132


2 Answers

Go into PuTTY, and then log into MySQL. Run the following in MySQL:

show processlist;

That will show a list of all running processes. You will probably be able to find the query that is locking your tables as it will likely be the longest running query with a bunch of other queries waiting for the lock release. Make a note of the process id of this query.

Then run:

kill [PROCESSID];

That will kill the process. Of course you need to do this as the user that has privilege to stop the query that was started (so use the same user or root if you have to).

like image 142
Mike Brant Avatar answered Nov 14 '22 23:11

Mike Brant


Use a MySQL console or some other tool to run the query SHOW PROCESSLIST to see the active query.

And the run the query kill 123 to kill a query/connection with id 123.

like image 26
Puggan Se Avatar answered Nov 14 '22 23:11

Puggan Se