Skip to content

Instantly share code, notes, and snippets.

@rubymerchant
Created March 27, 2015 05:34
Show Gist options
  • Save rubymerchant/28a154a90f53e30559ff to your computer and use it in GitHub Desktop.
Save rubymerchant/28a154a90f53e30559ff to your computer and use it in GitHub Desktop.
Rename Database
#!/usr/bin/env bash
mysql -e "DROP DATABASE $2;"
mysql -e "CREATE DATABASE $2;"
for i in $(mysql -Ns $1 -e "show tables");do
echo "$1.$i -> $2.$i"
mysql -e "rename TABLE $1.$i to $2.$i"
done
mysql -e "DROP DATABASE $1"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment