Avinash
Avinash

Reputation: 801

explicitly lock row while updating record in mysql

I want to add explicit lock on row which is currently being updated and I also want to remove the same lock explicitly, after updating that row in mysql.

I know there is inbuilt locking system of mysql but I want add it explicitly as well.

Upvotes: 0

Views: 1225

Answers (1)

Lukas Eder
Lukas Eder

Reputation: 220762

You could of course issue a

SELECT .. FOR UPDATE

statement before the actual update. To release the lock again, commit the transaction. Read about locking reads here. But according to that documentation, that would do the same as simply issuing the UPDATE statement itself:

A SELECT ... FOR UPDATE reads the latest available data, setting exclusive locks on each row it reads. Thus, it sets the same locks a searched SQL UPDATE would set on the rows.

Upvotes: 2

Related Questions