Home ›
Export and re-import a database with Drush and the command lineExport and re-import a database with Drush and the command line
Submitted by Benjamin Melançon on July 27, 2010 - 11:20am
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
Comments
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 http://drush.ws/#sql-sync
Post new comment