title: mysql - locking rows while running transaction
body: <p>I have a transaction which takes a while to complete. I want to protect the affected rows from being updated from outside the current transaction</p>
  
  <p>What is the best practice to do so?</p>
  
  <p>First it would be good if other queries outside the transaction still can read the rows so my application doesn't do a complete hold while doing the work.</p>
  
  <p>When the transaction starts I will change/update a value in one column in each row so it will make a write lock right? Other queries outside of the current transaction can still read the rows (I don't care if old or new values are fetched), but not write to them?</p>
  
  <p>When the current transaction is complete the write lock is freed and other queries can write to the rows again?</p>
  
  <p>Is this the best practice or is there a better way?</p>
  
  <p>I use InnoDB engine for all tables</p>