User login

Export and re-import a database with Drush and the command line

These are run from the project's web root, example/web, so that drush can run, but the database itself is stored outside the web root, example/db.

On the export side:

drush sql-dump > ../db/development.sql

On the import side:

drush sql-connect < ../db/development.sql

expands to:

mysql -hlocalhost -uexample -pyMsx2rIP drupal-example < ../db/development.sql

(Agaric internal note: For getting database from a site on a server, Agaric's rake command rake test vlad:commit and rake prod vlad:commit handle this (as well as committing files). Stefan, who created this system, would like to move away from including the database and files in the project version control repository.)

Searched words: 
drush sql import database mysql import database db dump


forget the fancy back-tick quotes, use drush sqlc

Good post. Instead of using the ` backticks around sql-connect, with the latest drush, you can use drush sqlc < ../db/file.sql and avoid having to pipe into a command execution.

I don't know any express advantage, but it at least looks cleaner :)

drush sql-sync

do you folks know the drush sql-sync command?
using aliases (and ssh), it dumps and syncs dbs across installations.
take a good look at it

Post new comment

The content of this field is kept private and will not be shown publicly.
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.
  • You can use Markdown syntax to format and style the text. Also see Markdown Extra for tables, footnotes, and more.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <img> <blockquote> <small> <h2> <h3> <h4> <h5> <h6> <sub> <sup> <p> <br> <strike> <table> <tr> <td> <thead> <th> <tbody> <tt> <output>
  • Lines and paragraphs break automatically.

More information about formatting options

By submitting this form, you accept the Mollom privacy policy.