mysql for update 如果事务一直没有提交会不会这表数据一直锁在那里
迷茫
迷茫 2017-04-17 16:27:28
0
1
1228

mysql for update 锁住了一条或多条数据,或者是整个表 如果事务一直没有提交(比如服务器挂掉了)会不会这表数据一直锁在那里

迷茫
迷茫

业精于勤,荒于嬉;行成于思,毁于随。

reply all(1)
巴扎黑

No. After the client connection is disconnected, the lock will be automatically released.

Client 1

set AUTOCOMMIT = 0;
BEGIN;
SELECT * FROM articles WHERE id=1 FOR UPDATE ;

Client 2

set AUTOCOMMIT = 0;
BEGIN;
SELECT * FROM articles WHERE id=1 FOR UPDATE ;

At this time, client 2’s query will be stuck. Until client 1 commit or rollback . However, if client 1 directly closes the window and disconnects, client 2 can also directly obtain the lock. Explain that when the client disconnects, the lock will be automatically released. commitrollback 。但是,如果客户端1直接关闭窗口断开连接,客户端2也能直接拿到锁。说明客户端断开时,会自动释放锁

那么问题来了,客户端1断开连接后,是自动 rollback

Then the question is, after client 1 disconnects, does it automatically rollback? 🎜
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template