How to delete all data in a table in MySQL?
There are two methods to delete all data from a MySQL table.
- Use the DELETE statement to remove all rows from a table.
DELETE FROM 表名;
For example, to delete all data in a table named “users”:
DELETE FROM users;
- Delete all rows in a table using the TRUNCATE TABLE statement.
TRUNCATE TABLE 表名;
For example, to delete all data in a table named “users”:
TRUNCATE TABLE users;
The difference between these two methods lies in the fact that the DELETE statement deletes data line by line, while the TRUNCATE TABLE statement deletes the entire table and recreates an empty table with the same structure. Therefore, if you just want to delete all data in the table without preserving the table structure, the TRUNCATE TABLE statement is more efficient.