Skip to content

Instantly share code, notes, and snippets.

@icyrizard
Last active October 27, 2016 13:43
Show Gist options
  • Save icyrizard/5928ae359a6cf99f3ae3187411689cc9 to your computer and use it in GitHub Desktop.
Save icyrizard/5928ae359a6cf99f3ae3187411689cc9 to your computer and use it in GitHub Desktop.
Copy a Mysql database to another database
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