{
"$type": "site.standard.document",
"canonicalUrl": "https://rickymoorhouse.uk/blog/2010/2010-09-15-mysql-locking",
"path": "/blog/2010/2010-09-15-mysql-locking",
"publishedAt": "2010-09-15T15:17:56.000Z",
"site": "at://did:plc:r53zv4vpzeihop3aliwyejlu/site.standard.publication/3mos5q3a7jf2w",
"tags": [
"MySQL",
"tech"
],
"textContent": "After experimenting a bit with MySQL locking today, I thought I'd make a note of what I'd discovered:\n\nTo create a lock, you need to use:\n\n \n <code>LOCK TABLES table1 [READ |WRITE], table2 [READ |WRITE]</code>\n\n \n\nREAD is used to stop other people changing the table while you read from it.\nWRITE is used to stop other people reading the table while you write to it.\n\nOnce you have issued a LOCK TABLES statement, you will not have access to any tables you didn't include.\n\nWhen you have finished, you can issue the UNLOCK TABLES command.\n\nThe lock remains until you issue the UNLOCK TABLES command, your session ends, you start a transaction or your client is disconnected.\n\nThe MySQL locking mechanism is no use if you need to lock something between PHP requests, unless you have a separate process running persistently to maintain the connection to the database.",
"title": "MySQL Locking"
}