Is it possible to get an explicit, independent lock on a given row with MySQL?
What I want is:
- Read a row, and acquire a lock on it; if the row is already locked, wait for the lock to be released
- Perform some processing
- Write the row, and release the lock
I thought that SELECT FOR UPDATE would be my solution, but because it requires an explicit transaction, I can't do the following:
- Read & lock row 1
- Read & lock row 2
- Do something...
- Write & release row 2
- Do something...
- Write & release row 1
(or invert steps 4. and 6.)
Basically, I want to be able to explicitly acquire & release a lock on any row at any time, without having to wait to release all the locks at the same time using COMMIT
. Hence the idea to do it without a transaction.
Is that achievable with MySQL?