[Yandex Cloud documentation](../index.md) > [Yandex Managed Service for YDB](index.md) > Getting started

# Getting started with Managed Service for YDB

In this tutorial, you will create a [YDB](https://ydb.tech/en) database in Yandex Cloud and run a simple query against it using the Yandex Cloud [management console](https://console.yandex.cloud) or command line tools.

You can also work with a Yandex Managed Service for YDB database through:
* [YDB SDK](https://ydb.tech/docs/en//reference/ydb-sdk/)
* [YDB CLI](https://ydb.tech/docs/en//reference/ydb-cli/)
* [AWS SDK](docapi/tools/aws-sdk/index.md)
* [AWS CLI](docapi/tools/aws-cli/index.md)

## Getting started {#before-you-begin}

1. Navigate to the [management console](https://console.yandex.cloud) and log in to Yandex Cloud or sign up if not signed up yet.
1. If you do not have a folder yet, create one:

   1. In the [management console](https://console.yandex.cloud), in the top panel, click ![image](../_assets/console-icons/layout-side-content-left.svg) or ![image](../_assets/console-icons/chevron-down.svg) and select the [cloud](../resource-manager/concepts/resources-hierarchy.md#cloud).
   1. To the right of the cloud name, click ![image](../_assets/console-icons/ellipsis.svg).
   1. Select ![image](../_assets/console-icons/plus.svg) **Create folder**.
   
      ![create-folder1](../_assets/resource-manager/create-folder-1.png)
   
   1. Give your [folder](../resource-manager/concepts/resources-hierarchy.md#folder) a name. The naming requirements are as follows:
   
       * Length: between 3 and 63 characters.
       * It can only contain lowercase Latin letters, numbers, and hyphens.
       * It must start with a letter and cannot end with a hyphen.
   
   1. Optionally, specify the description for your folder.
   1. Select **Create a default network**. This will create a [network](../vpc/concepts/network.md#network) with subnets in each availability zone. Within this network, you will also have a [default security group](../vpc/concepts/security-groups.md#default-security-group), within which all network traffic will be allowed.
   1. Click **Create**.
   
      ![create-folder2](../_assets/resource-manager/create-folder-2.png)

## Create a database {#create-db}

You can create a database in a _serverless_ configuration or with _dedicated_ servers. For more information about differences between configurations, see [Serverless and dedicated modes](concepts/serverless-and-dedicated.md). You cannot change the database type once you create it.

{% note info %}

For the Amazon DynamoDB compatibility mode, use a serverless database configuration.

{% endnote %}

### Create a serverless database {#serverless}

{% list tabs group=instructions %}

- Management console {#console}

  1. In the [management console](https://console.yandex.cloud), select the folder for your database.
  1. Navigate to **Managed Service for&nbsp;YDB**.
  1. Click **Create a database**.
  1. Enter a **Name** for your database. The naming requirements are as follows:

     * Length: between 3 and 63 characters.
     * It can only contain lowercase Latin letters, numbers, and hyphens.
     * It must start with a letter and cannot end with a hyphen.

  1. Under **Database type**, select `Serverless`.
  
      You can leave the default parameters for your database and [update](operations/manage-databases.md#update-db-serverless) them later. For more information about database parameters, see [Creating a serverless database](operations/manage-databases.md#create-db-serverless).
  1. Click **Create a database**.

  Wait for the database to start. While being created, your database will have the `Provisioning` status. Once it is ready for use, its status will change to `Running`.

- Yandex Cloud CLI {#cli}

  1. If you do not have the Yandex Cloud CLI yet, [install and initialize it](../cli/quickstart.md#install).
  1. Create a database:

      ```bash
      yc ydb database create <DB_name> --serverless
      ```

      Where `<DB_name>` is the name of your database.

      Result:

      ```text
      done (6s)
      id: etn95g8jk8g0********
      folder_id: b1g7gvsi89m3********
      created_at: "2022-05-30T07:26:44Z"
      name: test
      status: PROVISIONING
      endpoint: grpcs://ydb.serverless.yandexcloud.net:2135/?database=/ru-central1/b1gia87mbaom********/etn95g8jk8g0********
      serverless_database:
        storage_size_limit: "53687091200"
      location_id: ru-central1
      backup_config:
        backup_settings:
        - name: daily
          backup_schedule:
            daily_backup_schedule:
              execute_time:
                hours: 17
          backup_time_to_live: 172800s
          type: SYSTEM
      document_api_endpoint: https://docapi.serverless.yandexcloud.net/ru-central1/b1gia87mbaom********/etn95g8jk8g0********
      monitoring_config: {}
      ```

      This will create a database with the default parameters. You can [update](operations/manage-databases.md#update-db-serverless) its parameters later on. For more information about database parameters, see [Creating a serverless database](operations/manage-databases.md#create-db-serverless).
  1. Check the status of the new database:

     ```bash
     yc ydb database get <DB_name>
     ```

     Where `<DB_name>` is the name of your new database.

     While being created, your database will have the `PROVISIONING` status. Once it is ready for use, its status will change to `RUNNING`.

{% endlist %}

### Create a database on dedicated servers {#dedicated}

{% list tabs group=instructions %}

- Management console {#console}

  1. In the [management console](https://console.yandex.cloud), select the folder for your database.
  1. Navigate to **Managed Service for&nbsp;YDB**.
  1. Click **Create a database**.
  1. Enter a **Name** for your database. The naming requirements are as follows:

     * Length: between 3 and 63 characters.
     * It can only contain lowercase Latin letters, numbers, and hyphens.
     * It must start with a letter and cannot end with a hyphen.

  1. Under **Database type**, select `Dedicated`.
  1. Under **Computing resources**, select the type and amount of [computing resources](concepts/resources.md#resource-presets).
  1. Under **Storage groups**, select the disk type and number of [storage groups](concepts/resources.md#storage-groups) that determines the total amount of storage.
  1. Under **Network**, configure the network:
     1. Optionally, in the **Public IP addresses** field, select **Assign** if you plan to query the database both from the Yandex Cloud network and the internet.

        {% note warning %}
        
        For Managed Service for YDB databases with external IP addresses, the outgoing internet traffic consumption is calculated based on the [current pricing policy](../vpc/pricing.md).
        
        Use grants to offset the charges for outgoing internet traffic generated by Managed Service for YDB usage.
        
        {% endnote %}

     1. Select an existing network from the **Cloud network** list or create a new one:
        1. Click **Create**.
        1. In the window that opens, enter a **Name** for the new network.
        1. Optionally, select **Create subnets**. Subnets in each availability zone will be created automatically.
        1. Click **Create network**.
     1. Under **Subnets**, select a subnet or create a new one for each [availability zone](../overview/concepts/geo-scope.md):
        1. Click **Create**.
        1. In the window that opens, enter a **Name** for the new subnet.
        1. Optionally, enter a **Description** for the subnet.
        1. Select the availability zone from the **Availability zone** list.
        1. Set the subnet address in [**CIDR**](https://en.wikipedia.org/wiki/Classless_Inter-Domain_Routing) format.
        1. Click **Create subnet**.

     You cannot change the settings of the **Network** section after the database is created.
  1. Click **Create a database**.

     Wait for the database to start. While being created, your database will have the `Provisioning` status. Once it is ready for use, its status will change to `Running`.

- Yandex Cloud CLI {#cli}

  1. If you do not have the Yandex Cloud CLI yet, [install and initialize it](../cli/quickstart.md#install).

  1. Create a cloud [network](../vpc/operations/network-create.md) and [subnets](../vpc/operations/subnet-create.md) for each [availability zone](../overview/concepts/geo-scope.md), if needed.
  1. Create a database:

      ```bash
      yc ydb database create <DB_name> \
        --dedicated \
        --resource-preset <configuration> \
        --storage type=<storage_type>,groups=<number_of_storage_groups> \
        --public-ip \
        --network-name default\
        --async
      ```

      Where:

      * `--resource-preset STR`: Configuration of the node computing resources. You can find the valid values in the **Configuration name** column of the table in [Database on dedicated resources](concepts/resources.md#resource-presets).
      * `--storage STR`: Storage type and number of [storage groups](concepts/resources.md#storage-groups) in `type=<storage_type>,groups=<number_of_storage_groups>` format. For the `ssd` type, a single storage group can store up to 100 GB of data.
      * `--public-ip`: Public IP address assignment flag. Without it, you will not be able to connect to your database from the internet.
      * `--network-name STR`: Name of the cloud network to create the database in. You can specify the `default` network.
      * `--async`: Asynchronous database creation flag.

      For more information about database parameters, see [Creating a serverless database](operations/manage-databases.md#create-db-serverless).

      Result:

      ```text
      done (7m18s)
      id: etnk1u65e4sh********
      folder_id: b1g7gvsi89m3********
      created_at: "2022-05-31T10:10:12Z"
      name: test-ded
      status: PROVISIONING
      endpoint: grpcs://lb.etnk1u65e4shtgj338va.ydb.mdb.yandexcloud.net:2135/?database=/ru-central1/b1gia87mbaom********/etnk1u65e4sh********
      resource_preset_id: medium
      storage_config:
        storage_options:
        - storage_type_id: ssd
          group_count: "1"
        storage_size_limit: "107374182400"
      scale_policy:
        fixed_scale:
          size: "1"
      network_id: enpqkm0od2bu********
      subnet_ids:
      - b0cmespgm8o3********
      - e2lif378n1pg********
      - e9b72lv142k4********
      dedicated_database:
        resource_preset_id: medium
        storage_config:
          storage_options:
          - storage_type_id: ssd
            group_count: "1"
          storage_size_limit: "107374182400"
        scale_policy:
          fixed_scale:
            size: "1"
        network_id: enpqkm0od2bu********
        subnet_ids:
        - b0cmespgm8o3********
        - e2lif378n1pg********
        - e9b72lv142k4********
        assign_public_ips: true
      assign_public_ips: true
      location_id: ru-central1
      backup_config:
        backup_settings:
        - name: daily
          backup_schedule:
            daily_backup_schedule:
              execute_time:
                hours: 17
          backup_time_to_live: 172800s
          type: SYSTEM
      monitoring_config: {}
      ```

  1. Check the status of the new database:

     ```bash
     yc ydb database get <DB_name>
     ```

     Where `<DB_name>` is the name of your new database.

     While being created, your database will have the `PROVISIONING` status. Once it is ready for use, its status will change to `RUNNING`.

{% endlist %}

## Query your database {#query}

{% list tabs group=instructions %}

- Management console {#console}

  1. In the [management console](https://console.yandex.cloud), select the folder with your database.
  1. Navigate to **Managed Service for&nbsp;YDB**.
  1. Select the database you created.
  1. Navigate to the **Navigation** tab.
  1. Click **New SQL query** and enter the query text:

     ```yql
     SELECT 1;
     ```

  1. Click **Run**.

     Check the query result below:

     ```text
     # column0
     0 1
     ```

- YDB CLI {#cli}

  1. If you do not have the Yandex Cloud CLI yet, [install and initialize it](../cli/quickstart.md#install).

  1. To manage your databases from the command line, [install](https://ydb.tech/docs/en//reference/ydb-cli/install) the YDB CLI.
  1. To authenticate the YDB CLI in Yandex Cloud, get an [IAM token](../iam/concepts/authorization/iam-token.md) and export it to the environment variable:

     ```bash
     export IAM_TOKEN=`yc iam create-token`
     ```

  1. Get the database endpoint and path:

     ```bash
     yc ydb database get ydb-prod
     ```

     Result:

     ```text
     ...
     endpoint: grpcs://ydb.serverless.yandexcloud.net:2135/?database=/ru-central1/b1gia87mbaom********/etnudu2n9ri3********
     ...
     ```

     Here, a part of the `grpcs://ydb.serverless.yandexcloud.net:2135` string contains the endpoint, while `/ru-central1/b1gia87mbaom********/etnudu2n9ri3********` specifies the database path.

  1. Query your database using the database endpoint and path:
  
     ```bash
     ydb \
       --endpoint grpcs://ydb.serverless.yandexcloud.net:2135 \
       --database /ru-central1/b1gia87mbaom********/etnudu2n9ri3******** \
       yql -s "SELECT 1;"
     ```

     Result:

     ```text
     ┌─────────┐
     | column0 |
     ├─────────┤
     | 1       |
     └─────────┘
     ```

{% endlist %}

## What's next {#whats-next}

* Learn more about [working with databases](operations/index.md).
* Read about the [service concepts](concepts/index.md).
* Learn more about the [YQL](https://ydb.tech/docs/en//yql/reference/).