CorefinityCorefinityDocs
Open the Control PanelControl Panel
Database · 3 of 3

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.

On this page

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.
  • An import replaces data. Take a backup first, so you can restore Database only (slower) to undo it.

Export or import with an AI assistant

ToThe assistant callsWhat happens
Exportcorestack_db_exportThe whole database is written to a download link, or to a file on the site outside the document root.
Importcorestack_db_importA 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.

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.

    Terminal
    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.

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.

    Terminal
    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

Import and export

Your assistant calls corestack_db_export.

tools/call
{
  "name": "corestack_db_export",
  "arguments": {
    "site_id": 4211,
    "target": "transfer",
    "compression": "zstd"
  }
}
Was this helpful?
Open in ClaudeOpen in ChatGPT