Created
June 3, 2024 14:39
-
-
Save notz/a8f6d698058f809716f32027ed4faaf1 to your computer and use it in GitHub Desktop.
mysql create copy database statments
This file contains hidden or 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 @NewSchema := "www-staging-1"; | |
SET @OldSchema := "www"; | |
SELECT CONCAT("DROP TABLE IF EXISTS `", @NewSchema, "`.`", table_name, "`;\nCREATE TABLE `", @NewSchema, "`.`",table_name, "` LIKE `", TABLE_SCHEMA , "`.`", table_name, "`;\nINSERT INTO `",@NewSchema, "`.`", table_name, "` SELECT * FROM `", TABLE_SCHEMA , "`.`", table_name, "`;") | |
AS `sql` FROM information_schema.TABLES WHERE TABLE_SCHEMA = @OldSchema AND TABLE_TYPE != "VIEW"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment