Search code examples
mysqldata-migration

Data transfer between non-matching structured Mysql Database


How to transfer data from db1.tab1 to db2.tab2 ?

Here db2.tab2 have different field name from db1.tab1. I tried with mysql work bench but it is not giving 100% result.

I'm using Xampp and mysql 5.6.22

Thanks


Solution

  • Use below query.

    INSERT INTO db2.`tab2` ( `id`, `user_name`, `password`, `is_active` ) SELECT `user_id`, `name`, `pass`, `active` FROM db1.`tab1`;
    

    As you can see the column name are different in both tables.

    So you have to mention on which column of table2, you want to insert which column data from table1.