Reputation: 87
I have two databases in my phpmyadmin
test and test1
now I want to merge it into other database i.e test3
Database test
has 15 tables . Database test 2
has 23 tables so that database test 3
contain 15+23 i.e 38 table
I also check Merge two database into a single database and How can we merge two databases with identical schemas? link but not found any solution
How it can be done with the help of php??
Upvotes: 2
Views: 1700
Reputation: 22532
Using php file first of all you need to take dump of multiple database using exec()
and mysqldump
as
exec("mysqldump --user root -p --databases test1 test2 > file.sql");
This will export multiple database into one file now you can import database into test3 using
exec("mysql -u username -p test3 < file.sql");
Upvotes: 2
Reputation: 183
Assuming all of the table names are different and we are talking tables only (Im unsure on triggers and other operations) you could use the "Copy database to: " feature in PHPmyAdmin to do this follow these steps;
test1
Copy database to:
section and then enter test3
as the database you wish to migrate to.
test2
Upvotes: 1
Reputation: 1540
Since you mentioned phpmyadmin you can do this all in phpmyadmin.
First export both databases (test1 and test2) as SQL. You can follow instructions in this post. Then you can import both of these databases in into test3 using phpmyadmin also.
You probably want to make sure that there are no conflicts with table names to avoid test1 overwriting test2 tables (or vice versa). If you want to keep these tables separate then you can add a prefix to all tables but it really depends what you're trying to do. Since you're expecting 38 tables I am assuming that you don't want to mix the data.
Upvotes: 1