Skip to content

Instantly share code, notes, and snippets.

@puckbag
Last active August 29, 2015 14:04
Show Gist options
  • Save puckbag/3e42c192dd70c3e861ae to your computer and use it in GitHub Desktop.
Save puckbag/3e42c192dd70c3e861ae to your computer and use it in GitHub Desktop.
Transfer AMPPS db to MAMP
#!/bin/bash
# http://dev.mysql.com/doc/refman/5.5/en/copying-databases.html
PWD=`pwd`
# http://stackoverflow.com/a/3572105
realpath() {
[[ $1 = /* ]] && echo "$1" || echo "$PWD/${1#./}"
}
DBNAME=$1
DUMPDIR=`realpath "$DBNAME"`
AMPPS_BIN=/Applications/AMPPS/mysql/bin
AMPPS_USER=****
AMPPS_PASS=****
MAMP_BIN=/Applications/MAMP/Library/bin
MAMP_USER=****
MAMP_PASS=****
echo "DBNAME: $DBNAME"
## dump
echo "DUMPDIR: $DUMPDIR"
mkdir -p "$DUMPDIR"
rm -Rf "$DUMPDIR"/*.sql "$DUMPDIR"/*.txt
$AMPPS_BIN/mysqldump -u"$AMPPS_USER" -p"$AMPPS_PASS" --tab="$DUMPDIR" $DBNAME
## drop/create db
$MAMP_BIN/mysql -u"$MAMP_USER" -p"$MAMP_PASS" -e "DROP DATABASE IF EXISTS $DBNAME; CREATE DATABASE $DBNAME;"
## disable foreign key checks
$MAMP_BIN/mysql -u"$MAMP_USER" -p"$MAMP_PASS" -e "SET GLOBAL foreign_key_checks=0;"
## create tables
cat $DUMPDIR/*.sql | $MAMP_BIN/mysql -u"$MAMP_USER" -p"$MAMP_PASS" $DBNAME
## import data
$MAMP_BIN/mysqlimport -u"$MAMP_USER" -p"$MAMP_PASS" $DBNAME "$DUMPDIR"/*.txt
## enable foreign key checks
$MAMP_BIN/mysql -u"$MAMP_USER" -p"$MAMP_PASS" -e "SET GLOBAL foreign_key_checks=1"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment