[英]Mysql lock read a single row for innodb
需要帮助锁定阅读(选择)行
第二秒1:航站楼A
START TRANSACTION;
SELECT * FROM tbl_processor WHERE id=1 FOR UPDATE; /*Or using this statement : SELECT * FROM tbl_processor WHERE id=1 LOCK IN READ MODE; */
UPDATE tbl_processor SET content='Updated content'; #Original content was content='Original content'
SELECT SLEEP(10); #Just to sleep for testing purpose
COMMIT;
第二点2:航站楼B;
SELECT * FROM tbl_processor WHERE id=1;
#This will return result immediately with content='Original content'
-----> This is my problem... I do not want this statement getting not updated content. It should wait until the Terminal A process completed
更改第二个事务(终端B)以获得共享锁:
SELECT * FROM tbl_processor WHERE id=1 LOCK IN SHARE MODE;
我建议您在此处查看《 MySQL参考手册》中的相关信息:
https://dev.mysql.com/doc/refman/5.7/en/innodb-locking-reads.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.