This prevents anyone else from using the tables while you have them locked. It can also be used to execute a group of statements as a unit.
LOCK TABLES inventory WRITE
SELECT quantity FROM inventory WHERE item=”abc”
UPDATE inventory SET quantity=’123′ WHERE item=”abc”
UNLOCK TABLES
We use WRITE lock here because we need to modify the inventory table. If you are only reading tables, you can use a READ lock instead. This lets other clients read the tables while you’re using them, but prevents clients from writing to them.
If you’re using multiple tables, you must lock all of them before you execute the grouped queries.
LOCK TABLES inventory WRITE, customer READ
…
UNLOCK TABLES