- We will use the sql-dump command to export the database into a file. The command returns the output that needs to be redirected to a file:
$ drush @drupal.production sql-dump > ~/prod-dump.sql
- Navigate to your local Drupal site's directory and copy sites/default/default.settings.php to sites/default/settings.php.
- Edit the new settings.php file and add a database configuration array at the end of the file; this will be the database used by Drupal:
// Database configuration.
$databases['default']['default'] = [
'driver' => 'mysql',
'host' => 'localhost',
'username' => 'mysql',
'password' => 'mysql',
'database' => 'data',
'prefix' => '',
'port' => 3306,
'namespace' => 'Drupal\\Core\\Database\\Driver\\mysql',
];
- Using the sql-cli command, we can import the database dump that we created:
$ drush sql-cli < ~/prod-dump.sql
- The sql-sanitize command allows you to obfuscate user emails and passwords in the database:
$ drush sql-sanitize
- To verify that our information is imported sanitized, we will use the sql-query command to run a query against the database:
$ drush sql-query "SELECT uid, name, mail FROM users_field_data;"