问题
ddev currently lacks an export-db command (see https://github.com/drud/ddev/issues/767)
How can I export a database?
回答1:
As of ddev v1.4.0 (2018-11-14), there is a ddev export-db
command. You can do these things (from ddev export-db -h
):
ddev export-db >/tmp/db.sql.gz
ddev export-db --gzip=false >/tmp/db.sql
ddev export-db -f /tmp/db.sql.gz
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
.)
Original answer with in-container techniques: What I always do is this:
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).
However, I'm looking forward to the export-db command when it gets here.
Note also that starting with v1.1.0 you can use the ddev snapshot
command to save a copy of a database in the .ddev/db_snapshots directory. It's not a text .sql.gz file, but it's a good saved db.
回答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.
回答3:
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
回答4:
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
来源:https://stackoverflow.com/questions/50123540/how-can-i-export-a-database-from-ddev