Clear MySQL Database: TRUNCATE vs DELETE
One way to empty a database is to use the TRUNCATE TABLE statement to delete all data in the database while keeping the table structure and indexes intact. For example, to empty all data in a table named “table name,” you can use the following statement:
TRUNCATE TABLE 表名;
Alternatively, you can also use the DELETE statement to remove all data in a table, but this method may be slower than using the TRUNCATE TABLE statement because the DELETE statement deletes data row by row. The following statement can be used to delete all data in a table:
DELETE FROM 表名;
When using the TRUNCATE TABLE or DELETE statement to remove all data from a table, all records in the table will be deleted, but the table structure and indexes will remain unchanged.