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
| 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.
Export from the browser terminal
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_PASSWORDandAPP_DB_NAME, so there is no password to enter.Write the database to a file
Run the command below with your site's domain in the path. The folder above
htdocsis not served, so the file cannot be downloaded from the site.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.gzDownload 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
Upload the file
Upload the
.sql.gzfile over SFTP to the site's folder,/var/www/and the domain, not intohtdocs.Load it into the database
In the browser terminal, run the command below with your site's domain and the file's name.
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
Your assistant calls corestack_db_export.
{
"name": "corestack_db_export",
"arguments": {
"site_id": 4211,
"target": "transfer",
"compression": "zstd"
}
}