Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
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