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
- Export the source database, using mysqldump or phpMyAdmin.
- Transfer the file.
- Import into the destination database.
- Run a search and replace for the site URL, using a tool that handles serialised data.
- Update the configuration if credentials differ.
- 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.