Will MySQL lock the table after emptying the table data?

PHP developers, will the MySQL datasheet lock up when it empties the data? I don"t know much about the database.

Jan.15,2022

see how you use it. The drop time is longer, and the truncate time is much faster, but there is also a short lock, which is recommended when the business is idle.


delete from table
MyISAM : table write lock
InnoDB : row write lock (exclusive lock). A single delete affects only one piece of data, and a whole table deletion will have next-key lock, which is similar to a table lock

.

truncate
truncate is essentially a DDL operation, which is locked at the table level, but faster than delete . The disadvantage is that it cannot be rolled back and the trigger will not be triggered

.
Menu