Last active
November 9, 2015 20:41
-
-
Save bingalls/8cfa80640749d9ebbb4a to your computer and use it in GitHub Desktop.
Mysql hack, to rename databases
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/bash | |
# renameDatabase.sh Rename a Mysql database, by moving all its tables | |
if [ $# -ne 2 ];then | |
echo "Usage: `basename $0` srcDatabase destDatabase" | |
echo 'Both database schemas must already exist. Escape any spaces in password with "\"' | |
exit | |
fi | |
echo "About to bulk rename $1 tables into $2. Control-C to quit" | |
read -sp "Please enter root database password" PASSWORD | |
# Avoid completion; No column names; Silence column formatting | |
for i in `mysql -ANsu root $1 -p$PASSWORD -e "SHOW TABLES"`; do | |
mysql -ANsu root -p$PASSWORD -e "RENAME TABLE $1.$i TO $2.$i" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment