Skip to content

Instantly share code, notes, and snippets.

@michaelmior
Created August 26, 2011 16:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save michaelmior/1173781 to your computer and use it in GitHub Desktop.
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.
#!/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
@mceachen
Copy link

mceachen commented Apr 2, 2014

Depending on your database engine, foreign keys will point to the OLD_DB, even after the RENAME TABLE.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment