• Start

SurrealQL

/

Executing queries

Via CLI

In this section, you will explore SurrealQL queries using the SurrealDB CLI. The SurrealDB CLI provides a powerful command-line interface for writing, executing, and visualising SurrealQL queries in real-time.

To get started, install the SurrealDB CLI on your local machine.

After installing the SurrealDB CLI, you can start writing SurrealQL queries by running the surreal start command in your terminal. You can also add the --help flag to view the available options and commands.

To start a SurrealDB server, run the surreal start command, using the options below. This example serves the database at the default location (http://localhost:8000), with a username and password.

surreal start --user root --pass secret

The server is actively running, and can be left alone until you want to stop hosting the SurrealDB server.

Terminal start

Open a second terminal and connect with surreal sql. You can stay in the interactive REPL, or pipe a one-shot query.

To open a REPL:

Start a SurrealDB shell (local endpoint)
surreal sql --endpoint http://localhost:8000 --ns main --db main --user root --pass secret --pretty
Start a SurrealDB shell (in-memory)
surreal sql --endpoint memory --ns main --db main --user root --pass secret --pretty

To run a simple SELECT without staying in the REPL:

echo 'SELECT * FROM person;' | surreal sql --endpoint http://localhost:8000 --ns main --db main --user root --pass secret --pretty --hide-welcome

Terminal SQL

Learn more about the available commands and options in the SurrealDB CLI documentation.

Was this page helpful?