SurrealDB Docs Logo

Enter a search query

Import command

The import command imports a SurrealQL script file into a local or remote SurrealDB database server.

BEFORE YOU START

Make sure you’ve installed SurrealDB — it should only take a second!

Command options

ArgumentsDescription

-e / --endpoint / --conn

optional

Sets the url of the database server to connect to

-u / --user

required

Sets master username for the database

-p / --pass

required

Sets master password for the database

-t / --token

optional

Sets the authentication token to use when connecting to the server. Connect to SurrealDB using a JWT instead of user credentials

--ns

required

Sets the desired namespace in which to import data

--db

required

Sets the desired database into which to import data

Positional argument

ArgumentsDescription

file

required

Sets the the path to the file which should be imported

Example usage

To perform a SurrealQL database import from a local file, in a terminal run the surreal import command with the required arguments.

surreal import --conn http://localhost:8000 --user root --pass root --ns test --db test downloads/surreal_deal_v1.surql

Using token based authentication

surreal import --conn http://localhost:8000 --token <token> --ns test --db test downloads/surreal_deal_v1.surql
Note

The Import statement has a file size limit of 4 GiB per import, this prevents the import process from running out of memory and crashing. Please make sure your import file is under this limit.

OPTION IMPORT

The output of a database export includes a line that contains the keywords OPTION IMPORT. This command is used internally to ensure that side effects do not run when the data is imported, such as events and table views.

Command help

To see the help information and usage instructions, in a terminal run the surreal import --help command without any further arguments. This command gives general information on the arguments, inputs, and additional options for the import command.

surreal import --help

The output of the above command:

Import a SurrealQL script into an existing database Usage: surreal import [OPTIONS] --namespace <NAMESPACE> --database <DATABASE> <FILE> Arguments: <FILE> Path to the SurrealQL file to import Options: -e, --endpoint <ENDPOINT> Remote database server url to connect to [default: ws://localhost:8000] [aliases: conn] -u, --username <USERNAME> Database authentication username to use when connecting [env: SURREAL_USER=] [aliases: user] -p, --password <PASSWORD> Database authentication password to use when connecting [env: SURREAL_PASS=] [aliases: pass] -t, --token <TOKEN> Authentication token in JWT format to use when connecting [env: SURREAL_TOKEN=] --auth-level <AUTH_LEVEL> Authentication level to use when connecting [env: SURREAL_AUTH_LEVEL=] [default: root] [possible values: root, namespace, ns, database, db] --namespace <NAMESPACE> The namespace selected for the operation [env: SURREAL_NAMESPACE=] [aliases: ns] --database <DATABASE> The database selected for the operation [env: SURREAL_DATABASE=] [aliases: db] -h, --help Print help

Using environment variables

When using the surreal import command, you can also use environment variables to set the values for the command-line flags.

Important

Most of the flags mentioned in the command output above also mention a corresponding environment variables.

For example, the --username flag can be configured with the SURREAL_USER environment variable instead.

For more on the environment variables available for CLI commands or SurrealDB instances in general, see the environment variables page.

On this page

© SurrealDB GitHub Discord Community Cloud Features Releases Install