Document:
If you acquire a table lock explicitly with lock TABLES, you can request a READ LOCAL lock rather
than a READ lock to enable other sessions to perform concurrent inserts while you have the table
Locked.
To perform many INSERT and SELECT operations on a table real_table when concurrent inserts
is not possible, you can insert rows into a temporary table temp_table and update the real table
With the rows from the temporary table periodically. This can is done with the following code:
mysql> lock table T1;
Error 1064 (42000): You have a error in your SQL syntax; Check the manual-corresponds to your MySQL server version for the right syntax-use-near "at line 1
mysql> lock table T1 write;
Query OK, 0 rows Affected (0.00 sec)
mysql> INSERT INTO T1 select * from T2;
ERROR 1100 (HY000): Table ' T2 ' is not locked with LOCK TABLES
mysql> Lock table T2;
Error 1064 (42000): You have a error in your SQL syntax; Check the manual-corresponds to your MySQL server version for the right syntax-use-near "at line 1
mysql> lock table T2 write;
Query OK, 0 rows Affected (0.00 sec)
mysql> INSERT INTO T1 select * from T2;
ERROR 1100 (HY000): Table ' T1 ' is not locked with LOCK TABLES
mysql> Lock table T1 WRITE,T2 write;
Query OK, 0 rows Affected (0.00 sec)
mysql> INSERT INTO T1 select * from T2;
Query OK, 869 rows affected (0.01 sec)
records:869 duplicates:0 warnings:0
Mysql> unlocks;
Error 1064 (42000): You have a error in your SQL syntax; Check the manual-corresponds to your MySQL server version for the right syntax-use-near ' unlocks ' on line 1
mysql> unlock tables;
Query OK, 0 rows Affected (0.00 sec)
You can see that you can put the content that you want to insert into the T1 table on a temporary table T2 (temporary table), so that you can avoid locking the table behind select to ensure that you insert it into the table T1;
For parallel insert problems that display the specified lock tables (from other tables)