Skip to content

SurrealDB CLI

Using the database

surreal db is the database component. It starts a server, opens an interactive SurrealQL shell, moves data in and out, and checks that a server is ready. Everything after db is forwarded to the database unchanged, so every database flag and environment variable works the way its reference page describes.

The database is installed by the install script by default. If it is not installed, surreal db <command> offers to install it the first time you run it.

CommandUse it to
surreal db startRun a server, in memory or on disk
surreal db sqlOpen a SurrealQL shell, or pipe queries into a server
surreal db importLoad a SurrealQL file into a database
surreal db exportWrite a database out as a SurrealQL file
surreal db is-readyCheck that a server accepts connections
surreal db validateCheck that SurrealQL files parse
surreal db fixRepair storage issues
surreal db mlImport and export machine-learning models
surreal db mcpRun the Model Context Protocol server over stdio
surreal db versionPrint the database version, or a server's

Upgrading the database is not a database command. Use surreal upgrade db.

Start an in-memory server with a root user. It listens on 127.0.0.1:8000.

surreal db start --user root --pass secret

Add a storage path to keep the data between runs.

surreal db start --user root --pass secret surrealkv:mydata

A relative path is resolved from the folder you run the command in. See surreal db start for the storage engines, binding, TLS and capabilities.

In a second terminal, open a shell against it.

surreal db sql --username root --password secret --pretty

The shell connects to ws://localhost:8000 and the main namespace and database. Name others with --namespace and --database. To run queries from a script instead, pipe them in.

echo "SELECT * FROM person;" | surreal db sql --username root --password secret --hide-welcome

surreal db is-ready exits successfully once a server accepts connections, which suits a health check or a wait loop in a script.

surreal db start --user root --pass secret &
until surreal db is-ready --endpoint http://localhost:8000; do sleep 1; done

Export a database to a SurrealQL file, and import it into another.

surreal db export --endpoint http://localhost:8000 --username root --password secret --namespace app --database main backup.surql
surreal db import --endpoint http://localhost:8000 --username root --password secret --namespace app --database main backup.surql

Both commands need a namespace and a database. surreal db export writes to standard output when you give it no file, or - as the file, so it composes with other tools.

To import into or export from a SurrealDB Cloud instance, use surreal cloud instance import and surreal cloud instance export, which resolve the endpoint and credentials and then run these commands for you.

surreal db validate parses SurrealQL files without running them. With no argument it checks every **/*.surql file under the current folder, so it fits a pre-commit hook or a CI step.

surreal db validate
surreal db validate "schema/**/*.surql"

The launcher keeps several database versions side by side. Run one command against another version with +VERSION, or change the default with surreal use.

surreal +2.6.5 db export --endpoint http://localhost:8000 --namespace app --database main
surreal use db@2

See Managing components for installing, pinning and upgrading versions.

The database's commands also run without db, and print a warning that names the replacement.

surreal start
Output
warning: `surreal start` is deprecated; use `surreal db start`.

The set of commands that still run this way is closed: start, sql, import, export, isready, is-ready, validate, fix, ml, module and mcp, and database options placed before a command, as in surreal --log debug start. The warning goes to stderr and names only the command, never an argument, so it is safe in CI logs. A command the database adds later runs only as surreal db <command>. Change scripts and service definitions to the surreal db form.

Note

Docker and other container images run the database directly. Inside an image, the command is surreal start and not surreal db start, and the examples in Running with Docker use that form.

surreal db reads the same SURREAL_* variables as before. SURREAL_USER, SURREAL_PASS, SURREAL_NAMESPACE, SURREAL_DATABASE and the rest are listed on the database environment variables page. The launcher's own variables start with SURREAL_CLI_, and it never reads SURREAL_* itself, so the two sets stay apart.

Was this page helpful?