Skip to content

Instantly share code, notes, and snippets.

@PiJoules
Last active August 29, 2015 14:16
Show Gist options
  • Save PiJoules/748f779cab8105e55342 to your computer and use it in GitHub Desktop.
Save PiJoules/748f779cab8105e55342 to your computer and use it in GitHub Desktop.
Command for transferring contents of one database to another one
# [oldpassword] is the password used for the old database and [newpassword] is the one for the destination database
# there is also no space between the -p and [old/newpassword]
$ mysqldump -h oldhost -u oldusername -p[oldpassword] olddbname | mysql -h newhost -u newusername -p[newpassword] newdbname
# This command can also be spilt into 2 ones if you want to perform them one at a time by saving the data into a temporary file
$ mysqldump -h oldhost -u oldusername -p[oldpassword] olddbname > temp.sql
$ cat temp.sql | mysql -h newhost -u newusername -p[newpassword] newdbname
# Delete the temp.sql with `rm temp.sql`
# If done the second way, you can also choose not to include the password when typing the command and instead type it later
$ mysqldump -h oldhost -u oldusername -p olddbname > temp.sql
Password: [oldpassword]
... # data saved into temp.sql
$ temp.sql | mysql -h newhost -u newusername -p newdbname
Password: [newpassword]
... # data piped into new database
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment