Transferring a database by saving and restoring splits the job into two clean phases: you produce a self-contained dump (a logical or physical save) from the source, move that file to the destination, and restore it into a fresh database instance. The method works because the dump carries both schema and data in a portable format, so the target server never needs direct access to the source. The key condition is that the dump and restore tools must come from compatible database versions and engines, otherwise the restore can fail partway or silently lose objects.
This guide walks through prerequisites, ordered actions, verification, and the failure cases that trip people up, using MySQL-style mysqldump and PostgreSQL-style pg_dump/pg_restore as concrete examples. The same structure applies to other relational engines with minor tool swaps.
First, pin down what "saving" actually produces
A database save (dump) comes in two broad families, and choosing the right one determines everything downstream.
A logical dump reads the database through the server and writes SQL statements or a portable archive: CREATE TABLE, INSERT, sequence resets, indexes, and constraints. It's plain text or a custom compressed format. Logical dumps are version-tolerant across minor releases and let you restore into a different host, reorder objects, or skip tables. They're also slower on large datasets because every row is re-inserted and indexes rebuilt.
A physical save copies the underlying files or a consistent binary snapshot: a filesystem-level copy of the data directory, a storage snapshot, or a tool like Percona XtraBackup. Physical saves are fast to take and restore for big databases but are tied to the exact storage layout, file format, and usually the same major version. They're the wrong choice for a straightforward transfer across hosts unless you control both servers tightly.
For a "save and restore" transfer where you want portability and reproducibility, start with a logical dump. Reach for physical tooling only when the dataset is large enough that a logical reload window is impractical, and only when source and target match on engine version and configuration.
A third option—exporting to CSV and re-importing—belongs to data interchange, not full database transfer, because it typically skips indexes, constraints, triggers, and stored procedures. Don't confuse the two.
Prerequisites before you touch either server
Get these in place first; skipping them causes most of the pain later.
Confirm engine and version on both sides. Source and target major versions should match, or the target must be a newer compatible major. Restoring a dump from a newer major into an older server frequently fails on syntax. Check disk space on the target. A logical dump expands during restore because the server writes data plus rebuilds indexes and logs. As a working rule, budget at least the source data size multiplied by two or three for the target's free space, and keep room for the dump file on the intermediate host. Gather credentials with privileges to read all objects on the source (for dumps this includes routines, triggers, and events) and to create databases and users on the target. Decide on a maintenance window. A dump taken while writes continue captures an inconsistent mix unless you use a consistent snapshot option. Plan the save during low traffic or accept that you'll need the consistency flags described below. Choose a transfer channel with integrity checks: scp, rsync, object storage, or a direct pipeline. Verify checksums (for example sha256sum on both ends) before restoring.
Step-by-step: save the source database
The actions below use mysqldump; PostgreSQL equivalents appear after.
1: Capture a consistent snapshot. For MySQL with InnoDB tables, add --single-transaction so the dump reflects one point in time without locking writes. Add --routines --triggers --events to include stored programs, and --set-gtid-purged=OFF if you're moving to a server that manages GTIDs differently. A representative command: mysqldump --single-transaction --routines --triggers --events --databases appdb > appdb.sql For PostgreSQL, pg_dump -Fc -d appdb -f appdb.dump produces a custom-format archive that pg_restore can read selectively. 2: Decide whether to include CREATE DATABASE. The --databases flag in mysqldump emits the CREATE DATABASE and USE statements, handy when the target doesn't have the database yet. Omit it when you want to restore into a differently named database on the target. 3: Compress and record a checksum. appdb.sql can be large; pipe through gzip and store a SHA-256 alongside. This lets you detect a truncated transfer before it corrupts a restore. 4: Confirm the dump is complete. Check that the file ends with the tool's completion marker (for mysqldump, a trailing -- Dump completed comment line) and that its size is plausible against the source's reported data size. A missing completion line usually means the dump aborted.
For PostgreSQL, custom-format dumps include a table of contents you can inspect with pg_restore -l appdb.dump; confirm the objects you expect are listed before moving the file.
Success check at this stage: the dump file exists, has a completion marker, a matching checksum, and (for PostgreSQL) a table-of-contents listing that matches the source's object count.
Step-by-step: move and restore into the target
1: Create a clean target database rather than restoring on top of existing objects. In MySQL, CREATE DATABASE appdb; and select it. In PostgreSQL, createdb appdb. Restoring into a populated schema invites duplicate-key and "already exists" errors that obscure real problems. 2: Run the restore with error logging on. For MySQL: mysql appdb < appdb.sql (add --force only if you deliberately want to continue past errors, which you normally don't on a first attempt). For PostgreSQL custom archives: pg_restore -d appdb --exit-on-error appdb.dump. Stopping at the first error keeps the target in a known state. 3: Watch for the two classic failures. Version-skew syntax errors surface immediately as parse failures. Privilege errors appear when the dump references users or definers that don't exist on the target; pg_restore --no-owner --no-privileges and mysqldump's lack of DEFINER clauses help when moving between environments with different account names. 4: Rebuild what dumps don't carry. Logins, grants, replication settings, and server-level configuration aren't in a data dump. Recreate application users and permissions on the target explicitly, then confirm the application's connection string points at the new host.
PostgreSQL note: restoring a custom archive into a database that already contains the schema will fail on object creation. Use --clean only when you intend to drop and recreate objects, and test that decision on a scratch copy first.
Success check: the restore command exits with status 0 and no error lines; the target reports the expected database and table count.
Verify the transfer before you cut over
A clean exit from the restore tool is necessary but not sufficient. Run these checks:
Row counts per table. Compare SELECT COUNT(*) on the source and target for the largest and most critical tables. Small differences on tables with active writes are expected if you dumped a moving target; zero tolerance applies to static reference tables. Checksums of representative data. For key tables, compute an aggregate checksum on both sides (for example CHECKSUM TABLE in MySQL, or SELECT md5(string_agg(...)) in PostgreSQL over an ordered subset). This catches truncation that row counts miss. Schema objects. List tables, views, routines, triggers, and indexes on both sides and diff the lists. A dump that silently dropped a trigger will pass row counts but break application logic. A read and a write. Point a staging copy of the application at the restored database, read a record, and write one. This exercises constraints, triggers, and permissions in one motion.
Document the comparison results; if row counts or object lists disagree, stop before switching production traffic and re-examine the dump.
When the restore fails: matching symptoms to causes
Troubleshooting order matters. Start with reversible checks and stop when the fix requires changing server internals you don't own.
Symptom: restore aborts on syntax near a version-specific keyword. Likely cause: source newer than target major. Check: compare SELECT version() on both. Fix: restore into a target of equal or newer major; downgrading a dump is not generally supported.
Symptom: "Unknown database" or "database does not exist." Likely cause: dump was taken without --databases, or the target database wasn't created. Check: inspect the head of the SQL file for CREATE DATABASE. Fix: create the target database first, or restore with mysql < dump.sql.
Symptom: duplicate entry or "already exists" errors. Likely cause: restoring into a populated schema, or the dump includes CREATE statements that collide. Check: confirm the target schema is empty. Fix: restore into a fresh database or drop and recreate the schema first.
Symptom: access denied / defner errors during restore. Likely cause: dump references users or DEFINER clauses absent on the target. Check: grep the dump for DEFINER=. Fix: strip definers on import when policy allows, then re-grant application users explicitly.
Symptom: restore succeeds but application sees missing rows. Likely cause: dump captured an inconsistent snapshot of a live database, or a table was excluded by a filter flag. Check: compare row counts and re-inspect the dump command for --ignore-table or --exclude-table. Fix: retake the dump with consistency flags and the correct table scope.
Stop condition: if failures point to corrupted storage, replication divergence you can't explain, or a version mismatch where the target cannot be upgraded, hand the transfer to the database administrator or vendor support rather than continuing to force the restore.
Consistent snapshots and the moving-target problem
The most common silent failure isn't a syntax error; it's a logically consistent-looking restore of an inconsistent capture. If writes continue during the dump without a snapshot mechanism, you can capture a row in one table and a related row in another at different moments, producing orphaned foreign keys or totals that don't add up.
Use --single-transaction with InnoDB so the dump reads against one consistent view. For MyISAM or mixed engines, the equivalent protection is --lock-tables (briefly blocking writes) or accepting a cruder capture during a maintenance window. In PostgreSQL, pg_dump takes a consistent snapshot automatically, so the risk mainly lives on the MySQL side and on file-copy approaches. The practical rule: take the save during a quiet period even when you use consistency flags, and keep the window short by not running other heavy jobs alongside it.
Scope decisions: what a dump does and doesn't carry
A data dump transfers the database's objects and rows but is not a full server image. Things you'll typically need to handle yourself:
Users and grants. Recreate separate from the data restore; account names and roles are environment-specific. Server configuration. Buffer sizes, time zones, character sets, and replication topology are set on the server, not captured in the dump. Mismatched character sets (for example a latin1 source restoring into a utf8mb4 target) deserve an explicit check. Binary large objects and external files. Confirm whether your export includes large objects; some tools require dedicated flags. Files referenced by path won't travel with the dump. Sequences and auto-increment counters. Most logical dumps reset sequence values, but verify counters match the source so newly inserted rows don't collide on primary keys.
For a full server transfer, a logical per-database dump of each schema plus a separately managed user list is the usual, portable route; physical snapshots are the alternative when downtime or volume rules out logical reloads.
A worked size estimate to plan the window
Say the source database reports 40 GB of table data and 15 GB of indexes. A logical SQL dump typically lands around the data size plus header overhead, so roughly 40–45 GB before compression, and commonly 10–20 GB after gzip, depending on data compressibility. The restore is the slower half: the server writes rows and rebuilds 15 GB of indexes, and on a target with modest I/O budget you might see a few thousand inserts' worth of progress per second.
As an illustrative calculation only, if the target sustains 50 MB of writes per second and the effective work is about 60 GB of data-plus-index writing, that's roughly 1,200 seconds—about 20 minutes—just for storage, before lock waits and transaction overhead. Real throughput depends on hardware, row size, and index count, so measure the restore on a scratch copy before committing to a maintenance window. The actionable point: benchmark restore time on a copy, don't estimate it from dump size alone.
Choosing the method by scenario
| Scenario | Prefer | Why |
|---|---|---|
| Cross-host move, different minor versions | Logical dump (mysqldump / pg_dump -Fc) | Portable, version-tolerant, selective |
| Very large dataset, tight window | Physical snapshot / backup tool | Faster copy, but requires matching versions and layout |
| Moving one schema or a few tables | Logical dump with table filters | Smaller file, faster restore, fewer objects to reconcile |
| Environment-to-environment (staging to test) | Logical dump, excluding owners | Avoids privilege and definer clashes |
| Same-server schema rollback | Logical dump with --clean (PostgreSQL) | Safe to rebuild objects when intended |
Choose the logical path unless volume makes it impractical; the portability and error visibility are worth the extra restore time for most transfers.
What to keep in the transfer record
Before you close out the job, store the dump filename and checksum, the exact commands used on both sides, the source and target version strings, the row-count and schema-diff results, and the time of the snapshot. This record is what makes the transfer reproducible and lets the next person diagnose a discrepancy without re-inventing the process. When a future restore misbehaves, the record tells you whether the problem is new or was baked into the save.
One last practical note on the file itself: keep an uncompressed copy of the logical dump alongside the compressed one during the verification window, because you may need to inspect specific statements without decompressing tens of gigabytes. Then verify the dump opens with head or the tool's table-of-contents listing, confirm your checksum matches, and only then delete the intermediate copy.