2017-06-08 96 views
0

單行需要幫助鎖定讀取(選擇)行Mysql的鎖讀對於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 
+0

閱讀「事務隔離模式」。 –

回答