MySQL InnoDB: Difference Between `FOR UPDATE` and `LOCK IN SHARE MODE`

后端 未结 2 1031
故里飘歌
故里飘歌 2020-12-12 18:21

What is the exact difference between the two locking read clauses:

SELECT ... FOR UPDATE

and

SELECT ... LOCK IN SHARE MODE          


        
2条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-12 19:11

    For Update --- You're informing Mysql that the selected rows can be updated in the next steps(before the end of this transaction) ,,so that mysql does'nt grant any read locks on the same set of rows to any other transaction at that moment. The other transaction(whether for read/write )should wait until the first transaction is finished.

    For Share- Indicates to Mysql that you're selecting the rows from the table only for reading purpose and not to modify before the end of transaction. Any number of transactions can access read lock on the rows.

    Note: There are chances of getting a deadlock if this statement( For update, For share) is not properly used.

提交回复
热议问题