This is a script that renames a MySQL database quickly because it relies on MySQL "RENAME TABLE" to do the actual renames.
Just run like this:
$ ./my_rename_db.sh <oldname> <newname>
#!/usr/bin/env bash
MYSQLPARAMS="-uroot -pSECRETPASSWORD"
mysql $MYSQLPARAMS $1 -e "SELECT 1" > /dev/null || exit 1
mysql -e "CREATE DATABASE \`$2\` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;" $MYSQLPARAMS
for i in $(mysql -Ns $1 -e "show tables" $MYSQLPARAMS);do
echo "$1.$i -> $2.$i"
mysql -e "RENAME TABLE \`$1\`.\`$i\` to \`$2\`.\`$i\`" $MYSQLPARAMS || exit 1
done
mysql -e "DROP DATABASE \`$1\`" $MYSQLPARAMS || exit 1
http://stackoverflow.com/questions/67093/how-do-i-quickly-rename-a-mysql-database-change-schema-name
No comments:
Post a Comment