简体   繁体   中英

How we merge two database into new database using php

I have two databases in my phpmyadmin test and test1 now I want to merge it into other database ie test3

Database test has 15 tables . Database test 2 has 23 tables so that database test 3 contain 15+23 ie 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??

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");

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.

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;

  1. Select the database test1
  2. Go to the operations navigation item along the top
  3. Go to the Copy database to: section and then enter test3 as the database you wish to migrate to. 复制数据库到
  4. Repeat for test2

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM