Here is an example of how to select some data from a table on one database and insert into a table of a different database. I assumes that you are using the same mysql connection.
The MySQL USE command is used to select the appropriate database at the appropriate time. database1 is where the data is being selected from and database2 is where it is inserted to.
See Select from a database and insert into a different database Snippet