Skip to content

Instantly share code, notes, and snippets.

@gadelkareem
Last active June 20, 2016 16:54
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save gadelkareem/a16ea5e6d826c07043b8 to your computer and use it in GitHub Desktop.
Simple MySQL migration bash script
#!/usr/bin/env bash
set -e
mkdir -p /root/tmp
#migrate "original db params" "new db params" "new db name"
function migrate(){
mysqldump --skip-lock-tables --single-transaction --add-drop-table $1 > /root/tmp/${3}.sql
echo "CREATE DATABASE IF NOT EXISTS ${3};" | mysql $2
mysql --max_allowed_packet=1000M $2 $3 < /root/tmp/${3}.sql
rm -f /root/tmp/${3}.sql
}
migrate "-uolduser -poldpassword -h oldhost olddbname" "-unewuser -pnewpassword -h newhost" "newdbname"
#more migrates here ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment