Last active
April 17, 2023 07:11
-
-
Save ManiruzzamanAkash/3fd11a3be9e563d9c09a5901a415ce82 to your computer and use it in GitHub Desktop.
Delete all tables from a database MySQL
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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