Removes every table in the current MySQL database in a single operation.
Dropping only tables keeps the database object, users, and privileges intact while clearing data structures. This is handy in staging environments or when schemas must be rebuilt quickly.
The action is irreversible; foreign keys and views disappear, and applications that reference them break. Always back up with mysqldump --all-databases
or snapshot storage first.
Run SHOW TABLES;
or query information_schema.tables
. Confirm the count matches expectations before deletion.
Use GROUP_CONCAT
to build one long statement that lists each table, then execute it with PREPARE
.
Cursor through information_schema.tables
, concatenate each table name, and call EXECUTE
.
1) Backup. 2) Disable foreign key checks. 3) Generate dynamic SQL. 4) Execute. 5) Re-enable checks. 6) Verify with SHOW TABLES;
.
Run your migration tool or re-execute CREATE scripts for Customers
, Orders
, Products
, and OrderItems
. Validate with sample inserts.
Always wrap in a transaction when available, log executed SQL, and restrict to non-production environments via separate credentials.
See below.
No native single command exists; you must build a dynamic DROP statement.
Yes. Temporarily disable with SET FOREIGN_KEY_CHECKS=0;
.
Only from backups or point-in-time recovery; DROP is permanent.
You need DROP
privileges on each table or DROP
privilege for the database.
Add a NOT IN ('table1','table2')
filter in the WHERE table_name
clause when building the dynamic SQL.
TRUNCATE keeps the table structures. DROP removes them. TRUNCATE is slightly faster but unsuitable when you need to rebuild schemas.