How to Migrate data from one database table to another database table in Mysql

Migrate data MySQL Interview Questions

How to Migrate data from one database table to another database table in Mysql. The tables and columns got different names and insert data from one database table to another database table using mysql query, Then following query will be very useful for doing same task.

Also Read :Mysql Interview Question answer

Here is step for Migrate data from one database table to another database table in Mysql

Suppose you have 2 database cmp1, cmp2 and table name companies1, companies2 And your task is to insert data from second database table to first database table.
The tables columns are different.
First DB: cmp1.companies1

NameAddressEmailPhone

Second DB: cmp2.companies2

NmAddsemailPh
INSERT INTO cmp1.companies (Name, Address, Email, Phone) 
SELECT Nm, Adds, email, Ph FROM cmp2.companies2;

If you want to apply some condition on your query then you easily can.

INSERT INTO cmp1.companies (Name, Address, Email, Phone) 
SELECT Nm, Adds, email, Ph FROM cmp2.companies2 WHERE cmp2.status = 1;

Leave a Reply