Import a SQL database file to Codespaces
Only SQL database files that were exported from a WordPress install can be imported to a running codespace environment. For environments that are hosted on the VIP Platform, SQL database backup files can be downloaded from the application’s VIP Dashboard.
Limitation
The total available disk space on a Codespace virtual machine is 32 GB. The total combined size of an application’s codebase, VIP MU plugins, the machine’s Linux image, runtimes, and any imports or additions to the database must be less than 32 GB. For this reason, the allowed size of a database file to be imported will vary depending on the amount of disk space that remains available within the 32 GB limit.
Import a database file
Prerequisite
- The SQL database file for import must be located on a user’s local machine.
- A codespace environment must already be created and in a running state.
- Drag the file and drop the SQL file into the “Explorer” section of the VS Code interface in the browser tab.
- If the SQL file is archived, run a command in the VS Code interface terminal to expand it. For example, a file archived with gzip can be expanded by running the command:
gunzip example-file.gz
- In the VS Code tab labeled “Terminal“, import the file with WP-CLI command:
wp db import <file>
. For example, to import a file namedexample-file.sql
, the command would be formatted as:wp db import example-file.sql
- Retrieve the codespace environment’s Local Address value:
- Select the tab labeled “Ports“.
- In the row for “Application (80)”, select the value in the column labeled “Forwarded Address“. Three icons will be displayed at the right of the local address value.
- To copy the Local Address value, select the clipboard icon labeled “Copy Local Address“.
- In the tab labeled “Terminal“, use WP-CLI to run a search and replace and update the imported site address values in the database with the Local Address value of the codespace environment. For example, if the imported SQL file was exported from a site with the site address value
example.com
, and the codespace Local Address value isexample-80.preview.app.github.dev
, the WP-CLI command will be formatted as:
wp search-replace example.com example-80.preview.app.github.dev --all-tables --report-changed-only
- Flush the object cache with the WP-CLI command
wp cache flush
. - Delete the SQL file from the VS Code “Explorer” window by right-clicking on the file name and selecting “Delete Permanently” from the flyout menu.
Last updated: June 04, 2024