Search code examples
ddev

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?


Solution

  • 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.