Wednesday, July 1, 2015

How to restore a MySQL database with a different name

Possible scenarios:

  • You made a backup of db1 on one system, but want to restore it as db2 on another.
  • You want to rename your existing database, db1 to db2.

mysqldump -p  --databases db1 > db1_backup

On the new system (or the same system if you're renaming):
mysqladmin -p  create db2
Before running db1_backup through mysql, make sure db1_backup doesn't have the command "use db1" in it, otherwise you will keep overwriting the old database!
mysql -p db2 < db1_backup


0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home