Drupal and Drush: Import/Export SQL Database with Drush
Moving sites from one server to another can be a tedious task, however with command line and drush we can simplify this task into a few easy steps.
Export the database
# drush cc all && drush cc all
# drush sql-dump > /tmp/website-dump.sql
Clearing the cache first removes unwanted cached tables which make the SQL file quite large and can also cause problems on import with the “MySQL Server Gone Away” errors
Copy the database over to your other server
You can use whatever method you like (FTP, etc) but to keep things on the command line, let’s use secure copy.
# scp /tmp/website-dump.sql [email protected]_host:/tmp/website-dump.sql
If the site you wish to import to is on the same server, you can skip the step above
Use drush to import the database
Navigate to your drupal install and run “drush status” to make sure the database connection is there.
# drush sql-drop
# drush sql-cli < /tmp/website-dump.sql
Done.