How to copy data from Database to another Database?

Musa :

I have this structure:

Database1
New(table)
--categories(column)
----id - name - parent_id - created_at - updated_at

Database2
Old(table)
--categories(column)
----id - category - parent - created_at - updated_at

How can I copy the data of the categories from Database1 to Database2 via SQL?

Tushar :

Try this code

INSERT INTO Database1.new_table 
SELECT id,category as name,parent as parent_id,created_at,updated_at 
       FROM Database2.old_table

This query for copy database with current datetime

INSERT INTO Database1.new_table 
SELECT id,category as name,parent as parent_id,
       now() as created_at,now() as updated_at 
FROM Database2.old_table

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=25534&siteId=1