EXPORT and IMPORT Drupal DATABASE with DRUSH command

Drush is the ultimate tool and companion for Drupal and it does a great job in situations where we want to import or export our Drupal database with sqlc and sql-dump commands.

Below is the detail of how to use Drush to import and export the database.

Import Drupal database with Drush sqlc

Drush command "drush sqlc" can be used to import a database from an SQL dump file to a Drupal database.

Make sure to use the sql-drop command to drop the database first and then run the sqlc command to import data to Drupal's current database.

drush sql-drop -y
drush sqlc < ~/path/to/db-file.sql


Export Drupal database with Drush sqlc-dump

The best way to export or download the Drupal database is to first rebuild/clear the cache and then export DB with Drush sql-dump command.

Clearing the cache first will empty the cache tables in the database and significantly decrease the database size.

  1. To export Drupal database, the first step is to rebuild your cache before database export
    drush cr // For Drupal 8 and above
    drush cc // For Drupal 6 & 7
  2. Now run the drush sql-dump command with the destination argument to export the Drupal database to the desired destination. This will dump the database into a gzip file without cache table content.
    drush sql-dump --gzip --result-file=/path/to/db-file.sql


More resources: