rfay
rfay

Reputation: 12815

How can I export a database from ddev?

ddev currently lacks an export-db command (see https://github.com/drud/ddev/issues/767)

How can I export a database?

Upvotes: 14

Views: 18387

Answers (4)

rfay
rfay

Reputation: 12815

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.

Upvotes: 28

MonTea
MonTea

Reputation: 1300

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.

Upvotes: 3

Fedir RYKHTIK
Fedir RYKHTIK

Reputation: 9974

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

Upvotes: 1

Adedapo Ajuwon
Adedapo Ajuwon

Reputation: 403

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

Upvotes: 0

Related Questions