Andrew Fletcher published: 16 May 2022 (updated) 11 December 2023 1 minute read
These steps are for Drupal 8 and 9.
Export your database
Order here is important. First you want to clear all the Drupal caches. Then export / dump the db the sql database to a file in your home directory.
drush cr
drush sql-dump > path/to/your/file/ourpout/sql-dump-file-name.sqlor
drush sql-dump --extra-dump=--no-tablespaces --result-file=../sql/db-2022-12-07.sqlWithout having to manually set the date
drush sql-dump --extra-dump=--no-tablespaces --result-file=../sql/db-$(date +%Y-%m-$d).sql
Import Database
Begin by dropping all the tables in your database. Then with the db empty, import the sql dump back into your Drupal database.
drush sql-drop
drush sql-cli < /path/to/your/file/sql-dump-file-name.sqlor
drush sql-drop
drush sqlc < /path/to/your/file/sql-dump-file-name.sql