What happens when php code does not reach the release-mysql-lock stage?

As an example, with this script;

mysql_query("LOCK TABLES mytest WRITE;");

for ($i = 1; $i < 100000; ++$i) {
    mysql_query("INSERT INTO mytest (Value, Value2, Value3) VALUES ($i, $i, $i);");
}

mysql_query("UNLOCK TABLES;");

What happens if the script timeout / user computer crashes / something before the stage UNLOCK TABLES? Will mysql “notify” that the client requesting the lock has disconnected and canceled the lock accordingly, or will it be stuck indefinitely?

+3
source share
1 answer

According to MySQL docs:

If the connection for the client session ends abnormally, as usual, the server implicitly releases all table locks held by the session (transactional and non-transactional). If the client reconnects, the locks will no longer work.

+8
source

All Articles