mysql> FLUSH TABLES WITH READ LOCK;
What exactly does command do?
- Set the global read lock - after this step,
insert/update/delete/replace/alter statementscannot run
- Close open tables - this step will block until all statements started previously have stopped
- Set a flag to block commits
- Closes all open tables
- Locks all tables for all databases with a global read lock
- MySQL is in READ only mode, cannot WRITE anything, except one case (see below)
insert/update/delete/replace/alterstatements cannot run
FLUSH TABLES WITH READ LOCKdoes not prevent the server from inserting rows into the log tables
How to unlock and keep MySQL back to normal?
UNLOCK TABLESto release the lock
- The session that holds the lock can read the table (but not write it)
- It prevents other sessions from modifying tables during periods
- If you don’t keep this session open to keep Locking
- Other sessions can write into tables
- If you run
FLUSH TABLES WITH READ LOCKfor preparing
mysqldump, you must keep this session, and run
mysqldumpin another session.
- Because If you don’t keep, the
binlogmay be changed during this session
Need discussion? Go https://github.com/hieuhtr/Blog/issues/8