Deadlock found when trying to get lock; try restarting transaction
1213 – Deadlock found when trying to get lock; Try restarting transaction
one thing to remember is that the row lock and unlock of InnoDB are for primary key index. If the table is locked according to the index when querying, but not through the primary key when updating,
the process waiting to unlock the query will report 1213 error, and the program may return a null value
instance:
Table
solidgoods (table name)
solidgoodsid index
productid
businessid
start thread a
execution:
set autocommit = 0
select businessid from soldgoods where soldgoodsID = ‘ac63837c76222e4a5419e2529d775ae4’ for UPDATE;<
query result
start thread B
execute:
set autocommit = 0
select businessid from soldgoods where soldgoodsID = ‘ac63837c76222e4a5419e2529d775ae4’ for UPDATE;<
the query is waiting to be unlocked
at this time, it is executed in thread a:
update solidgoods set productid = 2 where business id =’0a527df4763c3dc71cbafebec5a8d787 ‘
the value of the lock table is not updated according to the primary key
thread B will appear:
[err] 1213 – deadlock found when trying to get lock; Try restarting transaction
if the statement executed in the last thread a is changed:
update soldgoods set productid = 2 where soldgoods id =’ac63837c76222e4a5419e2529d775ae4 ‘
modify the value according to the index
and then
commit
commit the transaction. Thread B can get the query value smoothly
Similar Posts:
- MySQL reports an error lock wait timeout exceeded; Try restarting transaction problem solving method
- MySQL Lock Error: Lock wait timeout exceeded [How to Solve]
- How to Solve MySQL Errno:1782 Error
- Lock wait timeout exceeded; try restarting transaction-Mysql [How to Solve]
- MySQL error 1205: lock wait timeout exceeded solution
- MySQL Execute update error: Error Code 1175 [How to Solve]
- [Solved] MYSQL ERROR 1093 – You can’t specify target table ‘readbook’ for update in FROM clause
- SQL Error: Table is specified twice, both as a target for ‘UPDATE’ and as a separate source for data
- Mysqldump common error reports and Solutions
- ORA-00054:resource busy and acquire with NOWAIT specified or timeout expired