Today, I used the command flush tables with read lock to solve database synchronization exceptions, so I learned the relevant knowledge of locking tables by the way.
1. FLUSH TABLES WITH READ LOCK
This command is a global read lock. After the command is executed, all tables in all libraries are locked read-only. It is generally used for database online backup. At this time, the write operation of the database will be blocked, and the read operation will proceed smoothly.
The unlock statement is also unlock tables.
2.LOCK TABLES tbl_name [AS alias] {READ [LOCAL] | [LOW_PRIORITY] WRITE}
This command is a table-level lock, which can be customized to lock a table. For example: lock tables test read; does not affect the write operations of other tables.
Unlock statements are also unlock tables.
These two statements need to pay attention to a feature when they are executed, that is, the implicitly committed statement. Unlock tables are implicitly executed when exiting the MySQL terminal. That is, if the table lock is to take effect, the dialog must be maintained.
PS MYSQL's read lock and wirte lock
read-lock: Allow other concurrent read requests, but block write requests, that is, you can read at the same time, but do not allow any writes. Also called shared lock
write-lock: other concurrent read and write requests are not allowed and are exclusive. Also called exclusive lock
Reference : http://blog.csdn.net/shootyou/article/details/6026735
Variations of FLUSH TABLES WITH READ LOCK and LOCK TABLES
Guess you like
Origin http://10.200.1.11:23101/article/api/json?id=326645130&siteId=291194637
Recommended
Ranking