patternsqlCritical
Restore mysql database with different name
Viewed 0 times
withdatabasedifferentmysqlnamerestore
Problem
How can we restore mysql database with different name from mysqldump file.
I dont't want to open dump file and edit it. Any other better methods?
I dont't want to open dump file and edit it. Any other better methods?
Solution
You can let mysqldump create the dump in such a way that it does not create or select the database.
EXAMPLE : You are dumping the database db1 and loading it into database db2
This will put in the CREATE DATABASE and the USE commands in the dump
This will not put in the CREATE DATABASE and the USE commands in the dump (this is what you want)
You can load it into another database (such as db2) in one of four(4) ways:
OPTION 1
OPTION 2
$ mysql -u... -p... -A -Ddb2
mysql> source /root/db1.sql
$ mysql -u... -p... -A
mysql> use db2
mysql> source /root/db1.sql
`
Give it a Try !!!
EXAMPLE : You are dumping the database db1 and loading it into database db2
This will put in the CREATE DATABASE and the USE commands in the dump
mysqldump -u... -p... --routines --triggers --databases db1 > /root/db1.sql
This will not put in the CREATE DATABASE and the USE commands in the dump (this is what you want)
mysqldump -u... -p... --routines --triggers db1 > /root/db1.sql
You can load it into another database (such as db2) in one of four(4) ways:
OPTION 1
$ mysqldump -u... -p... --routines --triggers db1 | mysql -u... -p... -A -Ddb2
OPTION 2
$ mysqldump -u... -p... --routines --triggers db1 > /root/db1.sql
$ mysql -u... -p... -A -Ddb2
OPTION 3
$ mysqldump -u... -p... --routines --triggers db1 > /root/db1.sql$ mysql -u... -p... -A -Ddb2
mysql> source /root/db1.sql
OPTION 4
$ mysqldump -u... -p... --routines --triggers db1 > /root/db1.sql$ mysql -u... -p... -A
mysql> use db2
mysql> source /root/db1.sql
`
Give it a Try !!!
Context
StackExchange Database Administrators Q#8869, answer score: 82
Revisions (0)
No revisions yet.