I have long heard that the two commands, lock tables and unlock tables , literally know that the function of the former is to lock the table and the latter is to unlock it. But how to use, how to use, not very clear. Today, in a detailed study, we finally figured out the usage of 2 people.
The lock tables command locks the table for the current thread. There are 2 types of locking, one is read lock, with command lock tables TableName read; The other is write lock, with command lock tables tablename write. The following are respectively described below:
1. Lock Table Read locks
If a thread obtains a read lock on a table, the thread and all other threads can only read data from the table, and no write operations are allowed.
Below we test, the test table is the user table.
Different threads can be implemented by opening multiple command-line MySQL clients: