Using InnoDB, do MySQL transactions lock newly created rows when BEGIN
is called, and then unlock them when commit is called? for example:
使用InnoDB, MySQL事务是否在调用BEGIN时锁定新创建的行,然后在调用commit时解锁它们?例如:
$query = "INSERT INTO employee (ssn,name,phone)
values ('123-45-6789','Matt','1-800-555-1212')";
mysql_query("BEGIN");
$result = mysql_query($query);
mysql_query("COMMIT);
Does the INSERT
statement lock that row until COMMIT
is called, or is it rolled back to prevent other concurrent connections from modifying it? If not, can you only lock a row within a transactions which blocks reads and any modifications by calling select FOR UPDATE?
插入语句是否锁定该行直到调用COMMIT,还是回滚该行以防止其他并发连接修改它?如果没有,那么只能在事务中锁定一个行,通过调用select进行更新来阻止读取和任何修改吗?
1 个解决方案
#1
3
Until the transaction is committed, the newly created record is invisible to other connections. Other connections cannot modify it, so there is no need to lock it.
在提交事务之前,新创建的记录对其他连接是不可见的。其他连接不能修改它,所以不需要锁定它。
#1
3
Until the transaction is committed, the newly created record is invisible to other connections. Other connections cannot modify it, so there is no need to lock it.
在提交事务之前,新创建的记录对其他连接是不可见的。其他连接不能修改它,所以不需要锁定它。