A deadlock occurs after MySQL InnoDB locks are unlocked.
[Error] Deadlock found when trying to get lock; Try restarting transaction
One thing to keep in mind is this: InnoDB's row lock and unlock are for primary key indexing. If the query is based on the index lock table, but the update is not through the primary key update, then waiting for the process of unlocking the query will be reported 1213 error, the program may return a null value instance: Table
soldgoods (table name)Soldgoodsid index ProductID BUSINESSID Open Thread A execution: set Autocommit=0;select businessid from Soldgoods where
Soldgoodsid= ' ac63837c76222e4a5419e2529d775ae4 ' for UPDATE; query results open thread B execution: Set Autocommit=0;select businessid from Soldgoods where
Soldgoodsid= ' ac63837c76222e4a5419e2529d775ae4 ' for UPDATE; the query waits to be unlocked this time in thread a execution: UPDATE soldgoods Set ProductID = 2 where
Businessid= ' 0a527df4763c3dc71cbafebec5a8d787 ' does not update the value of the lock table 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 changes: Update soldgoods Set ProductID = 2 where
Soldgoodsid= ' Ac63837c76222e4a5419e2529d775ae4 ' modifies the value according to the index and commits the transaction. Thread B will be able to get the query value smoothly.
A deadlock occurs after MySQL InnoDB locks are unlocked.