Skip to content

Instantly share code, notes, and snippets.

@notz
Created June 3, 2024 14:39
Show Gist options
  • Save notz/a8f6d698058f809716f32027ed4faaf1 to your computer and use it in GitHub Desktop.
Save notz/a8f6d698058f809716f32027ed4faaf1 to your computer and use it in GitHub Desktop.
mysql create copy database statments
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