Copy one table to another, with data, across databases - MySql / MariaDB

Populate one table from another, across databases.

Here's an example of populating a table from one database to another. 
Note: The user you're logged in as must have access to both databases.

//TRUNCATE TABLE newdb.destination_table_name;
INSERT INTO newdb.destination_table_name(id, user_id, field1, field2, ... )
SELECT `origin_table`.`id`,
    `origin_table`.`userid` as 'user_id',
    `origin_table`.`field1`,
    `origin_table`.`field2`,   ...
    
FROM `origindb`.`origin_table`;

 

Share this Post