If it's a bunch of data, it's probably best to use the migrate module.
I've recently a migration with migrate_plus, which comes with a migrate_example module you can copy. There's a yml file and a class for BeerNode that you can pretty much copy.
Then, set up your other database in settings.php:
$databases['example_other_db']['default'] = array (
'database' => 'lifecenter',
'username' => 'root',
'password' => 'root',
'prefix' => '',
'host' => 'localhost',
'port' => '',
'namespace' => 'Drupal\\Core\\Database\\Driver\\mysql',
'driver' => 'mysql',
);
Then, you can specify the source in the yml file for your importer.
source:
key: example_other_db
Then you basically map the fields to custom keys within your migrate class (see BeerNode.php in migrate_example module)
Here's some examples from my recent migration:
field_copyright_year: copyright
field_isbn: ISBN
field_volume: volume
field_pages_length: pagesLength
field_pub_title: bookJournalMagazineTitle
field_edition: edition
field_short_place: placePublished
field_shelf_code: callNumber
If you need something complex like an address field you can build it in your class, so the custom key is an array that matches what addressfield expects. There's a prepareRow function where you can do other queries
/**
* {@inheritdoc}
*/
public function prepareRow(Row $row) {
$row->setSourceProperty('companyName', $this->cleanString($row->getSourceProperty('companyName')));
$address = [
"langcode" => "EN",
"country_code" => "US",
"administrative_area" => "US-" . $row->getSourceProperty('state'),
"locality" => $row->getSourceProperty('city'),
"dependent_locality" => NULL,
"postal_code" => $this->cleanString($row->getSourceProperty('zip')),
"sorting_code" => NULL,
"address_line1" => $row->getSourceProperty('address1'),
"address_line2" => $row->getSourceProperty('address2'),
"organization" => $row->getSourceProperty('companyName'),
];
$row->setSourceProperty('address', $address);
return parent::prepareRow($row);
}
Then you run the migration from the command line.
1) run "drush ms" and make sure it lists your migration
2) run "drush mi example_migrate_machinename"
3) to pause import, do "drush mst example_migrate_machinename"
4) for other commands you can run " drush | grep migrate"