Topics

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 ...

Fork here

By continuing to use the site, you agree to the use of cookies. more information

The cookie settings on this website are set to "allow cookies" to give you the best browsing experience possible. If you continue to use this website without changing your cookie settings or you click "Accept" below then you are consenting to this.

Close