Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Need to clear MySQL InnoDB lock without restarting database

I have an MySQL InnoDB lock that is preventing a user from logging in. I don't care about the cause of this lock at the moment - I just need to clear the lock without restarting the database. Killing the query process does nothing FYI. Any suggestions? Thanks.

like image 717
modulaaron Avatar asked Jun 05 '12 19:06

modulaaron


People also ask

How do you avoid deadlock InnoDB?

To avoid deadlock, you must then make sure that concurrent transactions don't update row in an order that could result in a deadlock. Generally speaking, to avoid deadlock you must acquire lock always in the same order even in different transaction (e.g. always table A first, then table B).

How do I stop a MySQL table from locking?

Third option to prevent table locks with MySQL database is to use AUTOCOMMIT on the database level. This will prevent table locks from occurring unintentionally during report execution since all the transactions are committed after they are executed without additional commit commands.

How do I unlock a locked table in MySQL?

You can implicitly release the table locks. If the connection to the server terminates explicitly or implicitly all the locks will be released. You can release the locks of a table explicitly using the UNLOCK TABLES statement.

How can remove wait timeout lock in MySQL?

Dealing With a InnoDB Lock Wait Timeout When deploying a MySQL-based cluster, ClusterControl will always set innodb_rollback_on_timeout=1 on every node. Without this option, your application has to retry the failed statement, or perform ROLLBACK explicitly to maintain the transaction atomicity.


1 Answers

Here is how I wound up solving the problem:

mysql> show engine innodb status\G
*************************** 1. row ***************************
  Type: InnoDB
  Name: 
Status: 
=====================================
120710 18:05:37 INNODB MONITOR OUTPUT
=====================================
Per second averages calculated from the last 37 seconds
----------
SEMAPHORES
----------
OS WAIT ARRAY INFO: reservation count 208374, signal count 196902
Mutex spin waits 0, rounds 39211638, OS waits 80663
RW-shared spins 588505, OS waits 68505; RW-excl spins 3204502, OS waits 53586
------------
TRANSACTIONS
------------
Trx id counter 1 3626791829
Purge done for trx's n:o < 1 3625948819 undo n:o < 0 0
History list length 6754
LIST OF TRANSACTIONS FOR EACH SESSION:
...
---TRANSACTION 1 3625948818, ACTIVE 2892 sec, process no 1981, OS thread id 140020625811200
2 lock struct(s), heap size 368, 1 row lock(s), undo log entries 1

>>>>> MySQL thread id 14982, query id 232584561 localhost dbuser

Trx read view will not see trx with id >= 1 3625948819, sees < 1 3625948817

mysql> kill 14982;
Query OK, 0 rows affected (0.00 sec)

Note that the line with the >>>>> is where the MySQL thread ID is defined - it is this thread that should be killed.

Please see this post as well - very useful.

like image 77
modulaaron Avatar answered Oct 17 '22 05:10

modulaaron