If you use delayed-insert to insert data, you do not need to lock the table.
./Bin/mysqldump-uroot-proot -- lock-tables -- extended-insert -- opt -- quick -- master-data test>/home/zhanghong/opdir/tmp/test. SQL
--
Lock tables 'student 'WRITE;
/*! 40000 alter table 'student 'disable keys */;
Insert into 'student 'values (16, 'hhah', 3), (17, '22', 3), (18, 'ss', 18 );
/*! 40000 alter table 'student 'enable keys */;
Unlock tables;
Using delayed-insert will not lock the table
. /Bin/mysqldump-uroot-proot -- lock-tables -- delayed-insert -- extended-insert -- opt -- quick -- master-data test>/home/zhanghong/opdir/tmp/test. SQL
/*! 40000 alter table 'student 'disable keys */;
Insert delayed into 'student 'values (16, 'hhah', 3), (17, '22', 3), (18, 'ss', 18 );
/*! 40000 alter table 'student 'enable keys */;
/*! 40103 SET TIME_ZONE = @ OLD_TIME_ZONE */;
When a thread executes the DELAYED statement on a table, a management program thread is created (if it does not exist) to process all the DELAYED statements used in the table.
· The thread checks whether the hypervisor has previously obtained the DELAYED lock. If not, it notifies the hypervisor thread to perform this operation. The DELAYED lock can be obtained even if other threads have READ or WRITE locks on the table. However, the hypervisor will wait for all alter table locks or flush table locks to ensure that the TABLE structure is up-to-date.
· The thread executes the INSERT statement, but not writes rows to the table. Instead, it copies the final rows into a queue managed by the Management Program thread. The thread prompts a syntax error, which will be reported to the client.
· Before the INSERT operation, the INSERT return is complete. Therefore, the client cannot obtain the number of duplicate records from the server or the AUTO_INCREMENT value of the generated row. (If you use c api, for the same reason, the mysql_info () function will not return anything meaningful .)
· When a row is inserted into a table, the binary log is updated by the Management Program thread. When multiple rows are inserted, the binary log is updated when the first row is inserted.