Mysql 锁定为 innodb 读取单行
Mysql lock read a single row for innodb
需要帮助锁定阅读(select)行
第 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;
第二秒:航站楼 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
需要帮助锁定阅读(select)行
第 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;
第二秒:航站楼 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