---
title: "Connecting to SurrealDB"
description: "Create a Surreal client for a remote or embedded endpoint with new() or connect(), choose the engine at compile time or from a URL, select a namespace and database, and check the server from the Rust SDK."
canonical_url: "https://surrealdb.com/docs/reference/rust/concepts/connecting-to-surrealdb"
sdk: "Rust SDK"
sdk_version: "4.0.1"
surrealdb_version: "4.x"
last_modified: "2026-11-24T05:29:47Z"
---

> Full SurrealDB documentation index: https://surrealdb.com/docs/llms.txt

# Connecting to SurrealDB

Create a Surreal client for a remote or embedded endpoint with new() or connect(), choose the engine at compile time or from a URL, select a namespace and database, and check the server from the Rust SDK.

The Rust SDK talks to SurrealDB through a `Surreal` client. To start, create a client for an endpoint, [sign in](/docs/reference/rust/concepts/authentication.md), and select the namespace and database that later calls use.

`Surreal::new::<T>(address)` creates a client and connects it in one call, where `T` is the engine that reaches the endpoint, such as `Ws` for a remote server over WebSocket. `Surreal::init()` creates a client that is not connected yet, which suits a global static instance, and `connect()` connects it later. The `any` engine chooses the engine at runtime from the scheme of a URL, such as `ws://` or `mem://`, so the same code can open an embedded database or connect to a server.

Each method has its own page with its arguments and examples.

| Method | Description |
| --- | --- |
| [`Surreal::new()`](/docs/reference/rust/methods/new.md) | Creates a client and connects it to a local or remote database endpoint |
| [`Surreal::init()`](/docs/reference/rust/methods/init.md) | Creates a client that is not connected yet, typically for a global static instance |
| [`db.connect()`](/docs/reference/rust/methods/connect.md) | Connects a client to a local or remote database endpoint |
| [`db.use_ns()` and `db.use_db()`](/docs/reference/rust/methods/use.md) | Switch to a specific namespace and database |
| [`db.use_defaults()`](/docs/reference/rust/methods/use-defaults.md) | Selects the namespace and database set by `DEFINE CONFIG DEFAULT` |
| [`db.wait_for()`](/docs/reference/rust/methods/wait-for.md) | Waits for the connection, or for a database to be selected, before proceeding |
| [`db.health()`](/docs/reference/rust/methods/health.md) | Runs a lightweight health check on the connection |
| [`db.version()`](/docs/reference/rust/methods/version.md) | Returns the version of the server |
