How to do it...

The syntax is as follows:

mysql> LOCK TABLES table_name [READ | WRITE]

To unlock the tables, use:

mysql> UNLOCK TABLES;

To lock all tables across all databases, execute the following statement. It is used when taking a consistent snapshot of the database. It freezes all writes to the database:

mysql> FLUSH TABLES WITH READ LOCK;

Get MySQL 8 Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.