Reputation: 5640
Open 2 MySql command line consoles, and set autocommit=0.
console 1 (T1): select * from Employee where id=1 for update;
console 2 (T2): select * from Employee where id=1;
the result displayed. // should be locked
T2 should be locked when trying to select the employee. Right? It is select for upate.
console 2 (T2): update Employee set name ="FOO" where id=1;
locked as expected
Upvotes: 0
Views: 66
Reputation: 2014
No, you'd need to explicitly lock the read query using "LOCK IN SHARE MODE".
Otherwise, reads are not automatically locked in MySQL among separate connections. For more information see:
https://dev.mysql.com/doc/refman/5.7/en/innodb-locking-reads.html
In this document they provide an example where you can force locking - it is not default to lock.
Upvotes: 1