简体   繁体   English

MySQL事务是否锁定InnoDB中正在更新和/或选择的行

[英]Do MySQL transactions lock rows within InnoDB that are being updated and/or selected

Using InnoDB, do MySQL transactions lock newly created rows when BEGIN is called, and then unlock them when commit is called? 使用InnoDB时,MySQL事务会在调用BEGIN时锁定新创建的行,然后在调用commit时解锁它们吗? for example: 例如:

$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? 在调用COMMIT之前INSERT语句是否锁定该行,还是回滚以防止其他并发连接修改它? If not, can you only lock a row within a transactions which blocks reads and any modifications by calling select FOR UPDATE? 如果没有,你是否只能通过调用select FOR UPDATE来锁定一个阻止读取和修改的事务中的行?

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. 其他连接无法修改它,因此无需锁定它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM