Drupal MySQL Database Import and Export via Drush | Drupal 8

Drupal MySQL Database Import and Export via Drush

Submitted by editor on Mon, 07/25/2016 - 14:50
Question

How to Import and Export Drupal MySQL Database via Drush ?

Export Drupal 8 MySQL Database via Drush

drush cr
drush sql-dump > /pathto/mysql-dump-drupal8.sql

Import Drupal 8 and MySQL Database via Drush

drush sql-drop
drush sql-cli
mysql> source /pathto/mysql-dump-drupal8.sql

Export Drupal 7 MySQL Database via Drush

drush cc all
drush sql-dump > /pathto/mysql-dump-drupal7.sql

Import Drupal 7 MySQL Database via Drush (Same as Drupal 8)

//Method 1
drush sql-drop
drush sql-cli < /pathto/mysql-dump-drupal.sql
//OR :
drush sqlc < /pathto/mysql-dump-drupal.sql
If you have a error message like: "Access denied; you need the SUPER privilege for this operation" Try the Method 2

//Method 2
drush sql-drop
drush sql-cli
mysql> source /pathto/mysql-dump-drupal8.sql

 

Export to a gz compressed file

drush sql-dump | gzip > mysql-dump-drupal.sql.gz
drush sql-dump --gzip > mysql-dump-drupal.sql.gz

Import a GZ compressed file

gunzip < mysql-dump-drupal.sql.gz | drush sqlc

 

Options (Example)

drush sql-dump --data-only --gzip --tables-list="node,users"

More : https://drushcommands.com/drush-8x/sql/sql-dump/

 

Drush shortcuts

drush sql-cli = drush sqlc
drush sql-query = drush sqlq

Drush sql commandes

drush sql-cli        //Open a SQL command-line interface using Drupal's User and Password
drush sql-connect
drush sql-create    //Create a database
drush sql-drop         // Delete All tables of the current database
drush sql-dump         // Export current drupal Database to a file (like mysqldump)
drush sql-query     //Execute a query
drush sql-sanitize    //Run sanitization operations on the current database
drush sql-sync        //Copies the database contents from a source site to a target site. Transfers the database dump via rsync

Add new comment