MySQL uses locks for concurrency control. Whenever a client/thread acquires a lock, it will have exclusive access to that table or row (depending on the granularity of the lock). Other clients however, will be prevented from writing and possibly reading to/from the locked resource. The two main existing locks are:
READ LOCK – A read lock will allow the other
clients to read from the locked resource but not write to
it.
WRITE LOCK – a write lock will prevent the other
clients from reading or writing to the locked resource.
Also, different storage engines have different lock granularity. For example, MyISAM will lock the whole table while InnoDB will only lock the rows it needs.
Let’s try this out using a MyISAM table. We open two concurrent sessions and in the first lock the City table from the world database (get it …
[Read more]