官网地址:https://dev.mysql.com/doc/refman/8.0/en/lock-tables.html
A session that requires locks must acquire all the locks that it needs in a single LOCK TABLES
statement. While the locks thus obtained are held, the session can access only the locked tables. For example, in the following sequence of statements, an error occurs for the attempt to access t2
because it was not locked in the LOCK TABLES
statement:
mysql> LOCK TABLES t1 READ;
mysql> SELECT COUNT(*) FROM t1;
+----------+
| COUNT(*) |
+----------+
| 3 |
+----------+
mysql> SELECT COUNT(*) FROM t2;
ERROR 1100 (HY000): Table 't2' was not locke