Skip to content

Instantly share code, notes, and snippets.

@rvteja92
Created July 3, 2016 09:48
Show Gist options
  • Save rvteja92/9bd55e8b967198973f39e057b1f49fa1 to your computer and use it in GitHub Desktop.
Save rvteja92/9bd55e8b967198973f39e057b1f49fa1 to your computer and use it in GitHub Desktop.
Drop all the tables from database 'DATABASE_NAME'

Drop all tables from a database in MySQL

SET FOREIGN_KEY_CHECKS = 0; 
SET @tables = NULL;
SELECT GROUP_CONCAT(table_schema, '.', table_name) INTO @tables
  FROM information_schema.tables 
  WHERE table_schema = 'DATABASE_NAME'; -- specify DB name here.

SET @tables = CONCAT('DROP TABLE ', @tables);
PREPARE stmt FROM @tables;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
SET FOREIGN_KEY_CHECKS = 1;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment