Created
May 8, 2023 14:51
-
-
Save Oleksii909/d01a166790eb3d9506e767539fcd0358 to your computer and use it in GitHub Desktop.
Delete tables in database started with specific prefixes
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
-- Set up variable to delete ALL tables starting with 'allane_, default_, dp_, neuwagenabo_' | |
-- $(drush sql:connect) < drop-tables.sql | |
-- mysql -u drupal -pdrupal drupal < drop-tables.sql | |
SET GROUP_CONCAT_MAX_LEN=999999999; | |
SET @tbls = (SELECT GROUP_CONCAT(TABLE_NAME) | |
FROM information_schema.TABLES | |
WHERE TABLE_SCHEMA = 'drupal' | |
AND ( | |
TABLE_NAME LIKE 'allane_%' | |
OR TABLE_NAME LIKE 'default_%' | |
OR TABLE_NAME LIKE 'dp_%' | |
OR TABLE_NAME LIKE 'neuwagenabo_%' | |
) | |
); | |
SET @delStmt = CONCAT('DROP TABLE ', @tbls); | |
-- SELECT @delStmt; | |
PREPARE stmt FROM @delStmt; | |
EXECUTE stmt; | |
DEALLOCATE PREPARE stmt; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment