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.sql
or
drush sql-dump --extra-dump=--no-tablespaces --result-file=../sql/db-2022-12-07.sql
Without 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.sql
or
drush sql-drop
drush sqlc < /path/to/your/file/sql-dump-file-name.sql
Related articles
Andrew Fletcher
•
07 Jan 2025
Resolving Twig syntax errors in Drupal
The release of Drupal 10.4.0 sees stricter validation rules being applied to Twig templates, which can result in unexpected errors after an upgrade. One such issue involves the use of regular expressions within Twig's matches operator, leading to syntax errors that can break template rendering.This...
Andrew Fletcher
•
05 Jan 2025
A comprehensive guide to debugging and monitoring in Drupal like a pro
Observing colleagues work with Drush, it’s clear they have the basics down pat. Recently, I conducted a crash course in upskilling like a pro. Moving beyond the frequent commands many have already mastered, such as:drush cr
drush updb
drush statusThese commands are fantastic for quick tasks like...
Andrew Fletcher
•
26 Nov 2024
A technical journey to resolving line ending issues in Drupal installations
In the ever-evolving landscape of web development, technical challenges are par for the course. One such challenge recently encountered involved a Drupal installation, where the popular command-line tool Drush failed to execute correctly. This article delves into the issue, the diagnostic steps...