要摆脱LOCK TABLES查询,您需要使用UNLOCK TABLES。
让我们创建一个表-mysql> create table demo6
−> (
−> country_name varchar(100
−> )
−> );
借助insert命令将一些记录插入表中-mysql> insert into demo6 values('US');
mysql> insert into demo6 values('UK');
mysql> insert into demo6 values('AUS');
使用select语句显示表中的记录-mysql> select *from demo6;
这将产生以下输出-+--------------+
| country_name |
+--------------+
| US |
| UK |
| AUS |
+--------------+
3 rows in set (0.00 sec)
在这里,我只有上表的锁可供读取运算符使用。以下是查询-mysql> lock tables demo6 read;
以下是您尝试在上表中插入时的错误-mysql> insert into demo6 values('IND');
ERROR 1099 (HY000): Table 'demo6' was locked with a READ lock and can't be updated
如果您使用UNLOCK TABLES,则可以在同一表中插入记录-mysql> UNLOCK TABLES;
借助insert命令将一些记录插入表中-mysql> insert into demo6 values('IND');
使用select语句显示表中的记录-mysql> select *from demo6;
这将产生以下输出-+--------------+
| country_name |
+--------------+
| US |
| UK |
| AUS |
| IND |
+--------------+
4 rows in set (0.00 sec)