0

I have multiple independent processes, Scripts A and B, that each access the same table. I would like to Script A to read a record from the table then maybe modify that record (or maybe not).

The thing is that I need to keep Script B from accessing that particular record In the midst of that. Is there a manual lock perhaps? Something that will keep Script B out for just those few milliseconds?

Thanks

Daniel Kaplan
  • 701
  • 7
  • 19

1 Answers1

1

You don't want to lock the entire table right?

For InnoDB table a select...for update should do, it will lock the record (just add for update at the end of the query).

On your script A:

  1. Create a transaction
  2. Do a select for update
  3. If you want to update the record, do so.
  4. Commit the transaction when you finish.

On your script B do a select for update as well, it will wait until script A release the lock.

Julio Daniel Reyes
  • 5,489
  • 1
  • 19
  • 23