How can I export a database from ddev?

ddev currently lacks an export-db command (see )

How can I export a database?

4 Answers

Use the ddev export-db command. You can do many things (from ddev export-db -h):

ddev export-db --file=/tmp/db.sql.gz
ddev export-db -f /tmp/db.sql.gz
ddev export-db --gzip=false --file /tmp/db.sql
ddev export-db > /tmp/db.sql.gz
ddev export-db --gzip=false > /tmp/db.sql
ddev export-db myproject --gzip=false --file=/tmp/myproject.sql
ddev export-db someproject --gzip=false --file=/tmp/someproject.sql

In addition, don't forget about ddev snapshot, which is a great and quick way to make a quick dump of your db, but it's not as portable as a text-based dump. (See ddev snapshot -h and ddev restore-snapshot -h.)

Using traditional techniques inside the container:

Because DDEV has all the familiar tools inside the container you can also use commands like mysqldump and mysql and psql inside the container:

ddev ssh
mkdir /var/www/html/.tarballs
mysqldump db | gzip >/var/www/html/.tarballs/db.sql.gz
# or with explicit authentication
mysqldump -udb -pdb -hdb db | gzip >/var/www/html/.tarballs/db.sql.gz

or for Drupal/drush users:

ddev ssh
drush sql-dump --gzip >.tarballs/my-project-db.sql.gz

That places the dump in the project's .tarballs directory for later use (it's on the host).

See database management docs for more info.

2

I think it's very usefull to have the TYPO3 pendant for this, thanks to Outdoorsman for the comment on GitHub Issue above.

Outdoorsman wrote:

I'm coming from the TYPO3 CMS world and also agree this would be a good thing to have. I currently use

ddev ssh and ./vendor/bin/typo3cms database:export | gzip > project_name_db.sql.gz

if the typo3_console extension is installed via composer.

Also You could use Drupal console:

ddev start
ddev ssh
drupal database:dump
drupal database:restore --file db-2018-07-04-11-31-22.sql

To explain more on @rfay answer, i generally prefer drush cli, however, its based on preference .

ddev start
ddev ssh
drush sql:dump --result-file=../db-export.sql

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

You Might Also Like