DROP all tables removes every table in a MariaDB database by dynamically generating and executing DROP TABLE statements.
Dropping all tables removes every table and its data from the selected database. Views, triggers, and routines stay intact, but foreign-key relationships vanish with the tables.
Use it only in dev or staging when you need a clean slate—such as rebuilding schemas from migrations or loading fresh seed data. Never run it in production without a full backup.
Disable foreign-key checks, generate DROP statements from information_schema, then execute them in a single batch inside a transaction. This approach avoids constraint errors and lets you roll back if something fails.
```sqlSET FOREIGN_KEY_CHECKS = 0;```
```sqlSELECT GROUP_CONCAT(CONCAT('DROP TABLE IF EXISTS `', table_name, '`') SEPARATOR '; ') INTO @ddlFROM information_schema.tablesWHERE table_schema = 'your_db';```
```sqlPREPARE stmt FROM @ddl;EXECUTE stmt;DEALLOCATE PREPARE stmt;SET FOREIGN_KEY_CHECKS = 1;```
Yes. Adding START TRANSACTION;
before and COMMIT;
after the batch lets you ROLLBACK
if an error appears.
Without it, MariaDB refuses to drop child tables referenced by parents. Disabling checks lets you delete in any order, then re-enable constraints afterward.
• Always back up first. • Run in off-hours. • Use IF EXISTS
to avoid errors. • Re-enable foreign-key checks when done. • Verify with SHOW TABLES;
.
No native single command exists. You must dynamically build DROP TABLE statements from information_schema.
No. Only tables are dropped. Views, functions, and procedures remain.
Yes. Generate the SQL with a SELECT, pipe it to the mysql client, and run it as part of a CI/CD cleanup step.