Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ManiruzzamanAkash/3fd11a3be9e563d9c09a5901a415ce82 to your computer and use it in GitHub Desktop.
Save ManiruzzamanAkash/3fd11a3be9e563d9c09a5901a415ce82 to your computer and use it in GitHub Desktop.
Delete all tables from a database MySQL
USE [database_name];
SET FOREIGN_KEY_CHECKS = 0;
SET GROUP_CONCAT_MAX_LEN=32768;
SELECT GROUP_CONCAT(CONCAT('`', table_name, '`') SEPARATOR ',') INTO @tables
FROM information_schema.tables
WHERE table_schema = '[database_name]';
SET @tables = CONCAT('DROP TABLE IF EXISTS ', @tables);
PREPARE stmt FROM @tables;
EXECUTE stmt;
SET FOREIGN_KEY_CHECKS = 1;
// eg: [database_name] = my_database
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment