MySQL Error ERROR 1099 (HY000): Table was locked with a READ lock and can't be updated

MySQLMySQLi Database

To get rid of LOCK TABLES query, you need to use UNLOCK TABLES.

Let us create a table −

mysql> create table demo6
−> (
−> country_name varchar(100
−> )
−> );
Query OK, 0 rows affected (1.51 sec)

Insert some records into the table with the help of insert command −

mysql> insert into demo6 values('US');
Query OK, 1 row affected (0.11 sec)

mysql> insert into demo6 values('UK');
Query OK, 1 row affected (0.08 sec)

mysql> insert into demo6 values('AUS');
Query OK, 1 row affected (0.11 sec)

Display records from the table using select statement −

mysql> select *from demo6;

This will produce the following output −

+--------------+
| country_name |
+--------------+
| US           |
| UK           |
| AUS          |
+--------------+
3 rows in set (0.00 sec)

Here, I have a lock on the above table only for read operator. Following is the query −

mysql> lock tables demo6 read;
Query OK, 0 rows affected (0.00 sec)

Following is the error when you try to insert on the above table −

mysql> insert into demo6 values('IND');
ERROR 1099 (HY000): Table 'demo6' was locked with a READ lock and can't be updated

If you use UNLOCK TABLES, then you can insert records in the same table −

mysql> UNLOCK TABLES;
Query OK, 0 rows affected (0.00 sec)

Insert some records into the table with the help of insert command −

mysql> insert into demo6 values('IND');
Query OK, 1 row affected (0.09 sec)

Display records from the table using select statement −

mysql> select *from demo6;

This will produce the following output −

+--------------+
| country_name |
+--------------+
| US           |
| UK           |
| AUS          |
| IND          |
+--------------+
4 rows in set (0.00 sec)
raja
Published on 19-Nov-2020 10:54:04
Advertisements