Take the 2-minute tour ×
Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. It's 100% free, no registration required.

I am encountering deadlocks while trying to update multiple rows (a batch) using INSERT..ON DUPLICATE KEY UPDATE. Does MySQL lock all the rows in one batch or does it lock only the row it is updating at a point of time?

share|improve this question

1 Answer 1

This would depend on the Storage Engine.

  • MyISAM : Table-level locks are performed. Consequently, all rows are locked.

  • InnoDB : Row-level locks are employed. Since InnoDB is transactional, all rows are locked implcitly. Those locks would be visible when you run SHOW ENGINE INNODB STATUS\G. If you want to manually lock those rows beforehand to prevent sharing, you could run SELECT ... FOR UPDATE.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.