---
title: How to connect to a Database Instance
description: Learn how to connect to your PostgreSQL and MySQL Database Instances.
tags: postgresql mysql database-instance managed-database database
dates:
  validation: 2025-07-08
  posted: 2023-02-16
---
import Requirements from '@macros/iam/requirements.mdx'
import SshBastion from '@macros/databases/ssh-bastion.mdx'


<Requirements />

- A Scaleway account logged into the [console](https://console.scaleway.com)
- [Owner](/iam/concepts/#owner) status or [IAM permissions](/iam/concepts/#permission) allowing you to perform actions in the intended Organization
- A valid [API key](/iam/how-to/create-api-keys/)
- A [PostgreSQL or MySQL Database Instance](/managed-databases-for-postgresql-and-mysql/quickstart/)

## How to connect to a Database Instance through the public network

1. Click **PostgreSQL and MySQL** under **Databases** on the side menu. A list of your Database Instances displays.
2. Select the geographical region of the Instance you want to manage from the drop-down.
3. Click the database name or <Icon name="more" /> > **More info** to access the Database Instance information page.
4. Retrieve the Database Instance IP and port from the Database Instance information section.
    <Message type="note">
    Alternatively, you can click the **copy icon** under **Connection** to retrieve the database client connection command. This already includes your database IP and port.
    </Message>
5. Connect to your database with the database client of your engine.

    For MySQL, run the following command:
    ```bash
    mysql -h <ip-address> --port <port> -p -u <user_name>
    ```

    For PostgreSQL, run:
    ```bash
    psql -h <ip-address> -p <port> -U <username> -d rdb
    ```
6. Enter the password that you defined upon [Database Instance creation](/managed-databases-for-postgresql-and-mysql/how-to/create-a-database/).

  You are now connected to your Managed Database.

## How to connect to a Database Instance through a Private Network

[Private Networks](/vpc/concepts/#private-networks) allows you to enhance the security of your system's architecture by isolating it from the internet.

When using Private Networks, your application connects directly to your Database nodes without going through a Load Balancer.

This improves performance by reducing the latency between your application and your database nodes. It also increases the security of your databases, as Instances in your Private Network can directly communicate with your Database Instance, without passing through the public internet.

You can create new Database Instances to attach to your Private Network, or attach existing ones.

### How to attach a Database Instance to a Private Network

<Message type="note">
  You can only attach your Database Instance to one Private Network at a time.
</Message>

1. Click **PostgreSQL and MySQL** under **Databases** on the side menu. A list of your Database Instances displays.
2. Select the geographical region of the Instance you want to manage from the drop-down.
3. Click the database name or <Icon name="more" /> > **More info** to access the Database Instance information page.
4. Scroll to the **Network** section.
    <Message type="note">
      Alternatively, you can follow the next steps from the **Private Networks** tab. Click **+ Attach to a Private Network** to open the configuration pop-up.
    </Message>
5. Click **Attach Private Network** next to **Private endpoint**. A pop-up appears.
6. Choose whether to:
    - Select and attach an existing Private Network and select the network from the drop-down list.
        <Message type="important">
          The Database Instance must be attached to a Private Network in the same region.
        </Message>
    - Create and attach a new Private Network and enter the name of the network in the form.
        <Message type="important">
          If you select this option, a Private Network with default settings will be created in the same region as your Database Instance. Do not use a TLD (e.g. dev, cloud) as a name, to avoid conflicts.
        </Message>

    <Message type="note">
      - Your private IP addresses are automatically allocated. They are managed via an IP Address Manager (IPAM). You can retrieve them on the Private Network tab of your Database Instance. To allocate IPs manually, you can use the Scaleway API and CLI, or Terraform/OpenTofu.
      - You can also use internal DNS entries that point to the allocated IP address, which can be used to connect to the database. Refer to the [DNS resolution details](/vpc/reference-content/dns/#dns-resolution-details) section of the **Understanding Scaleway DNS for VPC and Private Networks** documentation page for a list of the formats resolved by the DNS service.
    </Message>
7. Click **Attach to Private Network** to conclude.

### How to connect to a Database Instance through a Public Gateway

<SshBastion />

### How to detach a Database Instance from a Private Network

1. Click **PostgreSQL and MySQL** under **Databases** on the side menu. A list of your Database Instances displays.
2. Select the geographical region of the Instance you want to manage from the drop-down.
3. Click the database name or <Icon name="more" /> > **More info** to access the Database Instance information page.
4. Click the **Private Networks** tabs. The Private Network configuration displays.
5. Click <Icon name="unlink" /> next to the static IP that you want to unlink from your Database Instance.
6. Click **Detach resource** to remove the Instance from your Private Network.

<Message type="note">
This action takes a few moments to complete. During this time, your Database Instance:
  - remains available,
  - goes into **Configuring** mode, and
  - all Database Instance configuration becomes unavailable
</Message>