Skip to content

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.

Prerequisite

  • The SQL database file for import must be located on a user’s local machine.
  • A codespace environment is already created and in a running state.
  1. Drag the file and drop the SQL file into the “Explorer” section of the VS Code interface in the browser tab. 
  2. 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
  3. In the VS Code tab labeled “Terminal“, import the file with WP-CLI command: wp db import <file>. For example, to import a file named example-file.sql, the command would be formatted as: wp db import example-file.sql
  4. 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“.
  5. 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 is example-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
  1. Flush the object cache with the WP-CLI command wp cache flush.
  2. 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: April 03, 2024

Relevant to

  • WordPress