Title: Import a SQL database file to Codespaces
Author: WordPress VIP Documentation
Published: April 3, 2024
Last modified: June 4, 2024

---

 1. [Local and cloud development](https://docs.wpvip.com/local-development/)
 2. [Developing with GitHub Codespaces](https://docs.wpvip.com/local-development/github-codespaces/)
 3. Import a SQL database file to Codespaces

#  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](https://docs.wpvip.com/vip-dashboard/backups/).

## Limitation

The total available disk space on [a Codespace virtual machine](https://docs.github.com/en/codespaces/overview#what-is-a-codespace)
is 32 GB. The total combined size of an application’s codebase, [VIP MU plugins](https://docs.wpvip.com/vip-go-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](https://docs.wpvip.com/local-development/github-codespaces/)
   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](https://developer.wordpress.org/cli/commands/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:
 5.  * 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**“.
 6. In the tab labeled “**Terminal**“, [use WP-CLI to run a search and replace](https://docs.wpvip.com/search-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-block-preformatted
    wp search-replace example.com example-80.preview.app.github.dev --all-tables --report-changed-only
    ```

 6. Flush the object cache with the WP-CLI command `[wp cache flush](https://developer.wordpress.org/cli/commands/cache/flush/)`.
 7. 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