Created
August 26, 2011 16:20
-
-
Save michaelmior/1173781 to your computer and use it in GitHub Desktop.
Simple script to move all tables from one database to another. Please don't use this in production as it could fail horribly. Also, RENAME table doesn't work on views, so they won't be migrated.
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
#!/bin/sh | |
OLD_DB=$1 | |
NEW_DB=$2 | |
TABLES=`echo "SHOW TABLES IN $1;" | mysql -NB` | |
IFS=" | |
" | |
for TABLE in $TABLES; do | |
$(echo "RENAME TABLE \`$1\`.\`$TABLE\` TO \`$2\`.\`$TABLE\`;" | mysql) | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Depending on your database engine, foreign keys will point to the OLD_DB, even after the RENAME TABLE.