Skip to content

Instantly share code, notes, and snippets.

@chrismealy
Forked from michaelmior/rename-db.sh
Created January 24, 2012 21:49
Show Gist options
  • Save chrismealy/1672925 to your computer and use it in GitHub Desktop.
Save chrismealy/1672925 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 product as 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment