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:
- VIP-CLI is installed and is updated to the most current version.
- A VIP Local Development Environment has been successfully created and is in a running state.
- A SQL database file (e.g., downloaded from Database Backups) must already be located on the local machine under the home directory of the current user.
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\
\file.sqlexample
-user
Ubuntu: /home/
/file.sqlexample
-user
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"
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. In this example command, a --search-replace
operation is included for the main site’s domain admin.example-site.com
, a network site with the assigned domain example-site.com
, and a third network site’s subdirectory domain admin.example-site.com/site-three
:
vip dev-env import sql--slug=example-site --search-replace="admin.example-site.com,admin.example-site.vipdev.lndo.site" --search-replace="example-site.com,example-site.vipdev.lndo.site" --search-replace="
/Users/example-user/file.sql
admin.example-site.com/site-three
,site-three.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.
Last updated: January 20, 2023