# Connection types

Memgraph Lab enables you to connect to a running Memgraph instance with:

- **Quick connect** - Allows you to quickly connect to a running Memgraph instance on `localhost:7687`.
- **Manual connect** - Starting from Lab 2.16, Memgraph Lab supports three types of connections to your Memgraph instances:
  1. [Connect to a standalone instance](#connect-to-a-standalone-instance)
  2. [Connect to a main or replica instance](#connect-to-a-main-or-replica-instance)
  3. [Connect to a HA cluster with automatic failover](#connect-to-an-ha-cluster-with-automatic-failover)

![](https://memgraph.com/docs/pages/data-visualization/lab-user-manual/connection-types/conn-type-select.png)

## Connect to a standalone instance

A standalone connection is a standard Bolt connection to a single Memgraph
instance. This option is commonly used in the following scenarios:

1. You're running Memgraph, but not with the default settings or the **Quick
   Connect** feature isn’t working. If you're unsure why Quick Connect isn't
   functioning, please refer to the [Troubleshoot connection
   issues](#troubleshoot-connection-issues) section.

2. You have [multi-tenancy](https://memgraph.com/docs/database-management/multi-tenancy) enabled in
   Memgraph and want to connect to a specific database.

3. You want to [connect to a coordinator instance](#coordinator-instance) that
   manages the cluster state in a high availability cluster. 

![](https://memgraph.com/docs/pages/data-visualization/lab-user-manual/connection-types/conn-type-standalone-input.png)

You will need to define:

- **Host**: Either `localhost`, `127.0.0.1`, `0.0.0.0`,
  or another appropriate address.
- **Port**: Enter `7687`, which Memgraph uses by default.
- **Logs port**: Default is `7444`, the port for web socket
  logs.
- **Database name**: Leave empty unless connecting to a
  [multi-tenant Memgraph instance](https://memgraph.com/docs/database-management/multi-tenancy).
- **Encrypted**: Choose whether the connection is
  encrypted (`SSL on` or `SSL off`).

Once you've successfully connected to Memgraph, you will see the following: 

![](https://memgraph.com/docs/pages/data-visualization/lab-user-manual/connection-types/conn-type-standalone-success.png)

In case you can't connect, please refer to the [Troubleshoot connection
issues](#troubleshoot-connection-issues) section.

### Coordinator instance

Standalone connections can also be used to connect to a
[Coordinator instance](https://memgraph.com/docs/clustering/high-availability). When
connecting to the Coordinator, the Lab UI changes to support only
cluster management queries. You will see components like query
execution, run history, query collections and query sharing.
The status bar will display the number of active and total
coordinators and data instances instead of the number of nodes,
relationships and memory/disk metrics.

![](https://memgraph.com/docs/pages/data-visualization/lab-user-manual/connection-types/conn-type-coordinator-success.png)

## Connect to a main or replica instance

Connecting to a [main or replica instance](https://memgraph.com/docs/clustering/replication)
is similar to connecting to a standalone instance with an additional
status bar difference upon successful connection: Replication status
overview.

![](https://memgraph.com/docs/pages/data-visualization/lab-user-manual/connection-types/conn-type-main-instance-success.png)

If **connected to a main instance**, the status bar will display
replication status, including the status of replicas and their
system and data replication status. The status bar will also
show that you are connected to the "Main" instance.

![](https://memgraph.com/docs/pages/data-visualization/lab-user-manual/connection-types/conn-type-replication-status.png)

If **connected to a replica**, you will not see the replication status
because replicas do not have the permission to display this
information. The status bar will show that you are connected to
the "Replica" instance.

![](https://memgraph.com/docs/pages/data-visualization/lab-user-manual/connection-types/conn-type-replica-instance-success.png)

## Connect to an HA cluster with automatic failover

[High availability](https://memgraph.com/docs/clustering/high-availability) is an enterprise
feature that supports automatic failover with a set of coordinators
and data instances. 

![](https://memgraph.com/docs/pages/data-visualization/lab-user-manual/connection-types/conn-type-ha-cluster-input.png)

To connect to the High availability cluster, choose the "HA Cluster" connection
type and input the **Host** and **Port** of **any coordinator instance**
(typical Memgraph’s high available cluster consists of three coordinator
instances).

![](https://memgraph.com/docs/pages/data-visualization/lab-user-manual/connection-types/conn-type-ha-cluster-success.png)

When connected to the HA cluster, you can run queries and manage data similar to
a standalone or main/replica instance connection. Additionally, the status bar
provides information about the **cluster status**, showing the status of each
coordinator and data instance.

![](https://memgraph.com/docs/pages/data-visualization/lab-user-manual/connection-types/conn-type-ha-cluster-status.png)

## Connection color

You can customize the connection color to help visually distinguish between
different environments.

![](https://memgraph.com/docs/pages/data-visualization/lab-user-manual/connection-types/conn-type-color-pick.png)

The selected color will appear below the status bar, making it easier to tell
connections apart when working with multiple Memgraph instances in the same Lab
session.

![](https://memgraph.com/docs/pages/data-visualization/lab-user-manual/connection-types/conn-type-color-success.png)

## Troubleshoot connection issues

Memgraph Lab detects if Memgraph is running on `localhost:7687` by default for
the **Quick Connect**. The environment variables that are responsible for Quick
Connect working as expected are:
- `QUICK_CONNECT_MG_HOST`: specifies the hostname or IP address
- `QUICK_CONNECT_MG_PORT`: specifies the port number, e.g. `- e
  QUICK_CONNECT_MG_PORT=7688`
- `QUICK_CONNECT_MG_IS_ENCRYPTED`: indicates whether the connection should be
  encrypted

The handling of the `QUICK_CONNECT_MG_HOST` environment variable differs based
on the operating system:

- **Mac or Windows**: The `host.docker.internal` hostname allows Docker
  containers to connect to the host machine. Set this as the value for
  `QUICK_CONNECT_MG_HOST` when running Lab on Mac or Windows to enable
  connection to Memgraph running on the host:

```
docker run -d -p 3000:3000 -e QUICK_CONNECT_MG_HOST=host.docker.internal --name lab memgraph/lab
```

- **Linux**: There's no need to set `QUICK_CONNECT_MG_HOST` as it defaults to
  `localhost`, assuming Memgraph is running locally on the host machine.

> **Note**
>
> If you didn't set `QUICK_CONNECT_MG_HOST` with Docker in advance or if you're
> running a desktop version of Memgraph Lab, you can create a new connection and
> specify `host.docker.internal` as the Host.
>
> ![Setting `host.docker.internal` as the Host](https://memgraph.com/docs/pages/data-visualization/install-and-connect/memgraph-host-docker-internal.png)
