Last active
October 27, 2016 13:43
-
-
Save icyrizard/5928ae359a6cf99f3ae3187411689cc9 to your computer and use it in GitHub Desktop.
Copy a Mysql database to another database
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
db=$1 | |
new_db=$2 | |
NUMARGS=$# | |
if [ $NUMARGS -eq 0 ]; then | |
echo "Usage ./$0 db new_db" | |
echo "Select one of the available databases:" | |
bash -c 'mysql -u root --execute="show databases"' | |
exit 1 | |
fi | |
echo "Generating file $db.sql" | |
mysqldump $db -u root > $db.sql && \ | |
mysqladmin create $new_db -u root && \ | |
mysql $new_db -u root < $db.sql | |
echo "Creating $new_db" | |
echo "Check if db created:" | |
bash -c 'mysql -u root --execute="show databases"' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment