A deadlock occurs after MySQL InnoDB locks are unlocked.

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.