---
title: "Import and export"
url: https://docs.corefinity.com/guides/sites/database/import-and-export
type: guide
last_updated: 2026-11-13
feature: database
related:
  - https://docs.corefinity.com/api/reference/database/reveal-site-database-login.md
  - https://docs.corefinity.com/api/reference/database/get-site-database.md
  - https://docs.corefinity.com/api/reference/database/get-site-database-operation.md
  - https://docs.corefinity.com/api/reference/database/create-site-database-user.md
  - https://docs.corefinity.com/api/reference/database/update-site-database-user.md
  - https://docs.corefinity.com/api/reference/database/delete-site-database-user.md
  - https://docs.corefinity.com/mcp/tools/corestack_db_credentials_get.md
  - https://docs.corefinity.com/mcp/tools/corestack_db_export.md
  - https://docs.corefinity.com/mcp/tools/corestack_db_import.md
  - https://docs.corefinity.com/mcp/tools/corestack_external_db_get.md
  - https://docs.corefinity.com/mcp/tools/corestack_external_db_user_add.md
  - https://docs.corefinity.com/mcp/tools/corestack_external_db_user_update.md
---
# Import and export

Export an environment's database to a file, or import a file into it, with an AI assistant or from the browser terminal.

## Before you start

- You can open the site in **Managed Websites**. Anyone who can open a site can export and import its database.
- The Control Panel has no import or export button. Use an AI assistant connected over MCP, or the [browser terminal](/guides/sites/access-and-security/browser-terminal).
- An import replaces data. [Take a backup](/guides/sites/backups/snapshots) first, so you can restore **Database only (slower)** to undo it.

## Export or import with an AI assistant

| To     | The assistant calls   | What happens                                                                                                                              |
| ------ | --------------------- | ----------------------------------------------------------------------------------------------------------------------------------------- |
| Export | `corestack_db_export` | The whole database is written to a download link, or to a file on the site outside the document root.                                     |
| Import | `corestack_db_import` | A plain, gzip or zstd SQL file is loaded. A safety backup is taken first, and on Production the assistant asks you for the site's domain. |

The import removes statements the site's database login may not run, such as `DEFINER` clauses. Files travel as transfers: see [Files and transfers](/mcp/files-and-transfers).

## Export from the browser terminal

1. **Open the terminal**

   Open the browser terminal on the environment to export. The shell holds the site's own database login in the variables `APP_DB_USER`, `APP_DB_PASSWORD` and `APP_DB_NAME`, so there is no password to enter.

2. **Write the database to a file**

   Run the command below with your site's domain in the path. The folder above `htdocs` is not served, so the file cannot be downloaded from the site.

   ```bash
   MYSQL_PWD="$APP_DB_PASSWORD" mariadb-dump --user="$APP_DB_USER" --host=127.0.0.1 \
     --single-transaction --quick --routines --triggers --events --no-tablespaces \
     "$APP_DB_NAME" | gzip > /var/www/example.com/export.sql.gz
   ```

3. **Download the file**

   Fetch the file over SFTP, then delete it from the site. The host, port and SFTP command are on [Connection details](/guides/sites/access-and-security/connection-details).

## Import from the browser terminal

1. **Upload the file**

   Upload the `.sql.gz` file over SFTP to the site's folder, `/var/www/` and the domain, not into `htdocs`.

2. **Load it into the database**

   In the browser terminal, run the command below with your site's domain and the file's name.

   ```bash
   gzip -dc /var/www/example.com/import.sql.gz | MYSQL_PWD="$APP_DB_PASSWORD" mariadb \
     --user="$APP_DB_USER" --host=127.0.0.1 --default-character-set=utf8mb4 "$APP_DB_NAME"
   ```

The import stops at the first statement the database refuses. Database users you add cannot create or drop tables, so an import runs as the site's own login.

To copy a database between two environments of one site, see Copy between environments.

## Automate this

**MCP:** [`corestack_db_export`](https://docs.corefinity.com/mcp/tools/corestack_db_export.md), scope `exec`

```json
{
  "name": "corestack_db_export",
  "arguments": {
    "site_id": 4211,
    "target": "transfer",
    "compression": "zstd"
  }
}
```

**Control Panel:** Managed Websites › your site › Site settings › Database ([https://manage.corefinity.com/go/database](https://manage.corefinity.com/go/database))

## Related

- [Backups](/guides/sites/backups/snapshots): Take a backup before a change.
- [Browser terminal](/guides/sites/access-and-security/browser-terminal): Open a shell on a site without SSH.
- [Database users](/guides/sites/database/database-users): Add, rotate and delete database logins.
