Today, the flush tables with read lock command was used to solve Database Synchronization exceptions, so I learned about the lock table by the way.
1. FLUSH TABLES WITH READ LOCK
This command is global read lock. After the command is executed, all tables in all databases are locked and read-only. It is generally used for online database backup. At this time, the database write operations will be blocked and the read operations 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 table-level locking. You can customize to lock a table. For example, lock tables test read does not affect write operations on other tables.
The unlock statement is also unlock tables.
When executing these two statements, you must note that the statements are implicitly submitted. When you exit the mysql terminal, unlock tables is implicitly executed. That is, to make the table lock take effect, you must keep the dialog.
P.S. MYSQL read lock and wirte lock
Read-lock: Other concurrent read requests are allowed, but write requests are blocked, that is, they can be read at the same time, but no write is allowed. Also called shared lock
Write-lock: exclusive is not allowed for other concurrent read and write requests ). Also called exclusive lock