Usage

Warning. A successful import replaces every live base table. Tables absent from the dump are renamed out of the live schema. The import does not merge data. Back up the target database before importing or use a dedicated review database.

Use the database name shown in the dashboard to import a dump into an existing managed MariaDB database.

prev db import <dashboard-database-name> <dump>

To attach the database and import a dump when creating a preview from your local project, run:

prev create . --db <name> --db-import <dump>

prev create supports repeatable --db flags. With --db-import, pass exactly one --db and create a new preview from a local directory. The CLI rejects --db-import with --source, --image, --to, --compose, or --demo.

The import starts only when the preview is starting or already running. If the preview fails before that, the database is unchanged. After the import, Prev waits for the preview to become healthy only if it was still starting when the import began. If that wait fails, the database may already have been replaced, and the CLI reports that the database was imported but the preview did not become healthy. If the preview was already running when the import began, the CLI can report success without waiting again. Check the preview after the import.

Database and plan requirements

SQL import requires an active managed MariaDB database attached to your API key.

Managed databases are not included on the Free plan. Upgrade to Agency or Teams, which include one by default, or to Individual with a Managed Databases add-on.

Managed databases require an included database on your plan or an active Managed Databases add-on. Agency and Teams include one by default. Individual needs the add-on.

URL replacement

To import a WordPress SQL dump, use prev db import. The dashboard database admin imports CSV or NDJSON data into one existing table. A successful CLI import replaces every live base table. It does not merge data. Prev looks for WordPress siteurl and home entries in an options table. prev create --db-import passes the new preview URL as the destination and preserves each option's source subdirectory, so siteurl and home can differ. With --feedback, Prev appends /__app to the preview URL, followed by each option's source path.

If WordPress is installed in a subdirectory, Prev keeps that path. On a feedback preview, a site that lived at /blog is served under /__app/blog/, not only at /__app/.

If exactly one active preview is attached to the database, prev db import without --replace-to uses that preview as the destination. If no active preview is attached, the import still replaces the live tables and leaves the detected WordPress URLs unchanged, so pass --replace-to when those URLs should change. If more than one preview is attached, the import stops and requires --replace-to. --no-replace skips URL replacement and does not require --replace-to.

prev db import <name> wordpress.sql --replace-to <preview-url>

prev create --db-import cannot be combined with --image. For an image preview, deploy with --db <name> first, then import with prev db import and pass the destination URL with --replace-to. That import does not attach the database to the preview, and it does not change wp-config.php inside an image that is already running. The image needs to read DATABASE_URL and use the imported table prefix. For --feedback, include /__app in --replace-to. Prev removes that prefix before the request reaches the image and sends it in X-Forwarded-Prefix. A standalone import cannot add that handling to an image that is already running, so the image must restore the prefix. Otherwise WordPress can redirect or link outside the feedback view.

Use these flags with prev db import:

  • --replace-from overrides the source URL.
  • --replace-to sets one destination URL. For WordPress, Prev trims trailing slashes and writes that same URL to both home and siteurl without appending the detected WordPress subdirectory. Include any shared subdirectory in the destination URL. If you pass only the preview origin, both options are set to that origin. If those options need different paths, use prev create --db-import, which appends each option's source path and inserts /__app before that path when --feedback is set. For an image preview launched with --feedback, include /__app in the single URL you pass to --replace-to, before any shared subdirectory, for example /__app/blog.
  • --no-replace skips URL replacement.

To replace URLs in a generic dump with no WordPress URL, pass both --replace-from and --replace-to. Replacement URLs must be absolute HTTP or HTTPS URLs without credentials, a query, or a fragment.

Local WordPress configuration

After a successful import, the CLI looks for wp-config.php in the current directory for prev db import or in the project directory for prev create. If WordPress was detected or the file exists, the CLI tries to update it with configuration that reads from DATABASE_URL and uses the detected table prefix and replacement URLs when available. If the CLI cannot update the file, it prints the PHP blocks and where to insert them.

When packaging a preview with --db-import, the CLI also tries to add runtime configuration to the packaged copy of wp-config.php so WordPress can read the imported prefix and URLs from the database.

Prev tries to configure the packaged wp-config.php when it can use the copy in the deployed project. It does not configure every file. If Prev leaves the file unchanged, the import can still replace the database, and editing a local copy afterward does not change the copy that was deployed.

Import job status

When the upload is accepted, the response includes an import ID. The job starts as queued, then can report running, replacing, and swapping before it ends as ready or failed. The CLI prints state changes and waits up to 30 minutes. Each database can have one import in progress at a time.

Closing the CLI after the upload is accepted does not cancel the import. A restart drops the status of an import whether it was still running or had already finished, so the import can no longer be looked up. The live tables may already have changed. Check the database before you import again.

Dump formats and limits

  • Upload a .sql, .sql.gz, or .zip file up to 1 GiB. A ZIP must contain exactly one .sql file and no nested archive. The SQL inside a compressed dump is also limited to 1 GiB.
  • Export base tables and data. The importer rejects empty dumps, views, triggers, routines, events, CREATE USER, CREATE DATABASE, and DROP DATABASE. If the dump names a storage engine, use InnoDB, MyISAM, or Aria.
  • The import fails before it replaces the live tables if a foreign key connects the imported or live tables to another database, whether the link points out of them or into them. Remove that link. Exporting the dump again does not remove a link that already exists on the target or on another database that points at it.
  • Each SQL statement must be small enough for the database to accept.
  • The import has a 30-minute deadline that starts with the upload.

Prev replaces the live base tables after the dump has been loaded and checked. A failure before that replacement leaves the live tables unchanged. If the final replacement cannot be confirmed, the import can report failed even though the live tables already changed. Check the database before you import again. If the imported database is over 1 GB, the import reports a size warning.