D
D
DrunkMaster2015-09-08 18:08:12
MySQL
DrunkMaster, 2015-09-08 18:08:12

Using LOCK TABLE in MySQL?

From the moment of reading until the moment of deletion, other scripts should not have read and write access to this database table.
Questions:
1. Can this LOCK TABLES syntax be used?
2. How to make sure that the table is really blocked?
3. If another script tries to call at the time of the lock, will it wait until the lock is removed and then still make a request, or will it immediately spit out an error and exit?

LOCK TABLES `".$SourceTable."` READ, `".$SourceTable."` WRITE;
    mysqli_query($link, " SELECT.... ");
    // операции с данными
    mysqli_query($link, " DELETE.... ");
UNLOCK TABLES;

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Max, 2015-09-09
@MaxDukov

1. no, not right.
blocking either READ or WRITE.
MySQL .
READ - everyone (both the process itself and others) can only read.
WRITE - the process that caused the lock can read and write, the rest smoke.
2. try to perform a forbidden action from another session (INSERT / UPDATE / DELETE for READ, anything for WRITE) - the request will "hang" until it is unlocked. Or until the timeout.
3. Will wait until timeout.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question