Last active
February 22, 2017 10:04
-
-
Save MekDrop/6d6b8b6bd9d535174ccf66bb927a0833 to your computer and use it in GitHub Desktop.
This generates one SQL to be used to move one database tables to other database
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
# Change these variables values | |
set @old_db='a'; | |
set @new_db='b'; | |
SET SESSION group_concat_max_len = 1000000; | |
# Don't change anything below | |
SELECT CONCAT('RENAME TABLE ' , GROUP_CONCAT(cmd SEPARATOR ', ')) 'sql' | |
FROM ( | |
SELECT CONCAT('`',@old_db,'`.`', TABLE_NAME, '` TO `',@new_db,'`.`', TABLE_NAME, '`') cmd | |
FROM information_schema.tables | |
WHERE TABLE_SCHEMA = @old_db | |
) a | |
LIMIT 1; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment