Knowledgebase

Syncing a Database Between Environments Print

  • developersgitdeployment, developers, database, staging, wordpress, email, phpmyadmin, backup, caching
  • 0

Moving data safely in the right direction.

THE SAFE DIRECTION

Production to staging or local. This gives realistic test data.

THE DANGEROUS DIRECTION

Staging to production. It overwrites everything written since the copy: orders, registrations, comments, content.

Only do this on a site with no live data, and take a backup first.

THE PROCEDURE

  1. Export the source database, using mysqldump or phpMyAdmin.
  2. Transfer the file.
  3. Import into the destination database.
  4. Run a search and replace for the site URL, using a tool that handles serialised data.
  5. Update the configuration if credentials differ.
  6. Clear caches.

FOR WORDPRESS SPECIFICALLY

WP-CLI can export, import and search-replace in a few commands, handling serialisation correctly.

Never run a raw SQL replace on a WordPress database. It corrupts serialised data.

ANONYMISING

If staging is less protected, replace customer email addresses and personal data after importing. A staging copy of a customer database is a real exposure.

LARGE DATABASES

Import in chunks, or raise time limits. A timed-out import leaves a partial database.


Was this answer helpful?
Back

Are you happy with your experience? Leave us a review on Trustpilot.


Trustpilot