Skip to content

Import a database to a VIP Local Development Environment

Full or partial SQL database files can be imported to a running VIP Local Development Environment. It is recommended to import database files after a VIP Local Development Environment is confirmed to be up and running and has been configured to run with locally cloned application code.

Full SQL database backups for VIP Platform environments can be downloaded on demand from the VIP Dashboard. Backup files include custom tables, and are compatible with the VIP Local Development Environment.

  • The SQL file can include all tables from the database of a WordPress single site or multisite install, or only a specific table—or set of tables—from that database.
  • The database table structure of WordPress multisites differs from the structure of single sites. To work as expected, a SQL file that originated from a multisite install should be imported to a VIP Local Development Environment that was created as a multisite.

Prerequisites

On the user’s local machine:

1. Identify the absolute local path of the SQL file

Example local paths for a SQL file named file.sql for a current user named “example-user”:

macOS: /Users/example-user/file.sql
Windows: C:\Users\example-user\file.sql
Ubuntu: /home/example-user/file.sql

2. Validate the SQL file

Verify that the SQL database file is correctly formatted for import with the vip import validate-sql VIP-CLI command. This example command is using the absolute local path from the macOS example in the previous step:

vip import validate-sql /Users/example-user/file.sql

Any errors reported by the validate-sql command must be resolved before importing the SQL file to the local environment.

3. Import the SQL file

Use the vip dev-env import sql command to import a SQL database file to a running local environment.

As part of the import process, the vip dev-env import sql command will automatically:

  • Clear the object cache.
  • Add a WordPress user with an Admin role and default login credentials to all local environment sites.

In this example, the command is importing a SQL database named file.sql to a local environment with an assigned --slug value example-site:

vip dev-env import sql/Users/example-user/file.sql--slug=example-site

During the import process, a --search-replace operation should be run to replace domain values in the SQL file with the domain of the local development environment.

In this example, the value example-site.com is replaced with example-site.vipdev.lndo.site during the import of file.sql to the local environment:

vip dev-env import sql/Users/example-user/file.sql--slug=example-site --search-replace="example-site.com,example-site.vipdev.lndo.site"

Database imports for multisites

SQL database files exported from a multisite install with more than one site on the network should include a --search-replace operation for each network site. For best results, the replacement values should be a sub-subdomain of the local environment and not a subdirectory.

The order in which the search and replace operations matters. In the example command below, three --search-replace operations are included in a single import command:

  • Occurrences of a network site’s subdirectory domain admin.example-site.com/site-three will be replaced with a sub-subdomain structure site-three.example-site.vipdev.lndo.site.
  • admin.example-site.com, an example domain value for site ID 1, will be replaced with admin.example-site.vipdev.lndo.site.
  • Occurrences of another network site’s domain example-site.com will be replaced with example-site.vipdev.lndo.site.
vip dev-env import sql/Users/example-user/file.sql--slug=example-site --search-replace="admin.example-site.com/site-three,site-three.example-site.vipdev.lndo.site" --search-replace="admin.example-site.com,admin.example-site.vipdev.lndo.site" --search-replace="example-site.com,example-site.vipdev.lndo.site"

Using WP-CLI commands to run additional search-replace operations may be necessary after the import is complete. To accurately run a search-replace operation, the command structure will depend on whether the search-replace is targeting an entire single site, multisite, or specific tables.

Sync a database

A database can be synced instead of imported to a VIP Local Development Environment. This option is limited to WordPress single site environments.

The database of a WordPress single site environment on the VIP Platform can be synced with the VIP-CLI command: vip dev-env sync sql.

Last updated: June 02, 2023

Relevant to

  • WordPress