Simple MySQL migration bash script
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
#!/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