Skip to content

Deleting all rows from a MySQL table is a common task in database management, particularly useful for resetting tables without altering their structure. This action should be performed carefully to ensure data integrity and to maintain the structure for future use. With the understanding of the potential consequences, let’s explore the two primary methods for deleting all rows from a MySQL table: DELETE and TRUNCATE.

How to delete all rows using DELETE FROM in MySQL?

To remove all rows actively from a table, use the DELETE FROM command. This method, being transaction-safe, allows for a rollback if encapsulated within a transaction. It also logs each row deletion, aiding in data recovery and auditing.

DELETE FROM table_name;

Substitute table_name with your specific table name. This command actively deletes all rows, keeping the table’s structure untouched.

How to truncate a table in MySQL?

For a more rapid deletion, especially with large tables, TRUNCATE TABLE serves as the go-to command. It performs faster since it doesn’t log each deleted row, although it records the truncation event and resets auto-increment counters.

TRUNCATE TABLE table_name;

Replace table_name with the actual table name. Be cautious: TRUNCATE TABLE operations are irreversible and do not trigger ON DELETE triggers.

Considerations before deletion

Actively consider the following before clearing all rows from a table:

  • Confirm you have a recent data backup for restoration needs.
  • Understand the full implications, especially if other tables are linked via foreign keys.
  • Be aware that DELETE FROM can be reversed with a ROLLBACK if it’s within a transaction, unlike TRUNCATE TABLE.
  • Review any application dependencies that might be affected by the data deletion.

By adhering to these steps, you ensure a safe deletion of all rows from your MySQL table while keeping its structure ready for future data.

Written by

Robert Cooper avatar

Robert Cooper

Senior Engineer at Basedash

Robert Cooper is a senior engineer at Basedash who builds full-stack product systems across SQL data infrastructure, APIs, and frontend architecture. His work focuses on application performance, developer velocity, and reliable self-hosted workflows that make data operations easier for teams at scale.

View full author profile →

Looking for an AI-native BI tool?

Basedash lets you build charts, dashboards, and reports in seconds using all your data.