tommo
tommo

Reputation: 1350

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? 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? If not, can you only lock a row within a transactions which blocks reads and any modifications by calling select FOR UPDATE?

Upvotes: 3

Views: 1198

Answers (1)

vidang
vidang

Reputation: 1771

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.

Upvotes: 3

Related Questions