[Yandex Cloud documentation](../../index.md) > [Yandex Managed Service for MySQL®](../index.md) > [Step-by-step guides](index.md) > Clusters > Managing cluster hosts

# Managing MySQL® cluster hosts

You can add and remove cluster hosts, as well as manage their settings. To learn how to move cluster hosts to a different [availability zone](../../overview/concepts/geo-scope.md), see [this guide](host-migration.md).

## Getting a list of cluster hosts {#list}

{% list tabs group=instructions %}

- Management console {#console}

  1. Navigate to **Managed Service for&nbsp;MySQL**.
  1. Click the name of your cluster and select the **Hosts** tab.

- CLI {#cli}

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

  The folder used by default is the one specified when [creating](../../cli/operations/profile/profile-create.md) the CLI profile. To change the default folder, use the `yc config set folder-id <folder_ID>` command. You can also specify a different folder for any command using `--folder-name` or `--folder-id`. If you access a resource by its name, the search will be limited to the default folder. If you access a resource by its ID, the search will be global, i.e., through all folders based on access permissions.

  To get a list of cluster hosts, run this command:

  ```bash
  yc managed-mysql host list \
     --cluster-name=<cluster_name>
  ```

  Result:

  ```text
  +----------------------------+----------------------+---------+--------+---------------+
  |            NAME            |      CLUSTER ID      |  ROLE   | HEALTH |    ZONE ID    |
  +----------------------------+----------------------+---------+--------+---------------+
  | rc1b...mdb.yandexcloud.net | c9q5k4ve7ev4******** | MASTER  | ALIVE  | ru-central1-b |
  | rc1a...mdb.yandexcloud.net | c9q5k4ve7ev4******** | REPLICA | ALIVE  | ru-central1-a |
  +----------------------------+----------------------+---------+--------+---------------+
  ```

  You can get the cluster name with the [list of clusters in the folder](cluster-list.md#list-clusters).

- REST API {#api}

  1. [Get an IAM token for API authentication](../api-ref/authentication.md) and put it into an environment variable:

      ```bash
      export IAM_TOKEN="<IAM_token>"
      ```

  1. Call the [Cluster.listHosts](../api-ref/Cluster/listHosts.md) method, e.g., via the following [cURL](https://curl.se/) request:

      ```bash
      curl \
          --request GET \
          --header "Authorization: Bearer $IAM_TOKEN" \
          --url 'https://mdb.api.cloud.yandex.net/managed-mysql/v1/clusters/<cluster_ID>/hosts'
      ```

      You can get the cluster ID with the [list of clusters in the folder](cluster-list.md#list-clusters).

  1. Check the [server response](../api-ref/Cluster/listHosts.md#yandex.cloud.mdb.mysql.v1.ListClusterHostsResponse) to make sure your request was successful.

- gRPC API {#grpc-api}

  1. [Get an IAM token for API authentication](../api-ref/authentication.md) and put it into an environment variable:

      ```bash
      export IAM_TOKEN="<IAM_token>"
      ```

  1. Clone the [cloudapi](https://github.com/yandex-cloud/cloudapi) repository:
     
     ```bash
     cd ~/ && git clone --depth=1 https://github.com/yandex-cloud/cloudapi
     ```
     
     Below, we assume that the repository contents reside in the `~/cloudapi/` directory.
  1. Call the [ClusterService/ListHosts](../api-ref/grpc/Cluster/listHosts.md) method, e.g., via the following [gRPCurl](https://github.com/fullstorydev/grpcurl) request:

      ```bash
      grpcurl \
          -format json \
          -import-path ~/cloudapi/ \
          -import-path ~/cloudapi/third_party/googleapis/ \
          -proto ~/cloudapi/yandex/cloud/mdb/mysql/v1/cluster_service.proto \
          -rpc-header "Authorization: Bearer $IAM_TOKEN" \
          -d '{
                "cluster_id": "<cluster_ID>"
              }' \
          mdb.api.cloud.yandex.net:443 \
          yandex.cloud.mdb.mysql.v1.ClusterService.ListHosts
      ```

      You can get the cluster ID with the [list of clusters in the folder](cluster-list.md#list-clusters).

  1. Check the [server response](../api-ref/grpc/Cluster/listHosts.md#yandex.cloud.mdb.mysql.v1.ListClusterHostsResponse) to make sure your request was successful.

{% endlist %}

## Adding a host {#add}

The number of hosts in Managed Service for MySQL® clusters is limited by the CPU and RAM quotas allocated to database clusters in your cloud. To review current resource usage, open the [Quotas](https://console.yandex.cloud/cloud?section=quotas) page and find the **Managed Databases** section.


{% list tabs group=instructions %}

- Management console {#console}

  1. Navigate to **Managed Service for&nbsp;MySQL**.
  1. Click the cluster name and navigate to the **Hosts** tab.
  1. Click **Create host**.
  1. Specify the following host settings:

     
     * Availability zone.
     * Subnet (if the required subnet is not on the list, [create it](../../vpc/operations/subnet-create.md)).
     * Select **Public access** to make the host accessible from outside Yandex Cloud, if required.


     * Host priority for promotion to master.
     * Host priority as a MySQL® replica for creating backups.

- CLI {#cli}

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

  The folder used by default is the one specified when [creating](../../cli/operations/profile/profile-create.md) the CLI profile. To change the default folder, use the `yc config set folder-id <folder_ID>` command. You can also specify a different folder for any command using `--folder-name` or `--folder-id`. If you access a resource by its name, the search will be limited to the default folder. If you access a resource by its ID, the search will be global, i.e., through all folders based on access permissions.

  To add a host to a cluster:

  
  1. To choose a subnet for your new host, get the list of all cluster subnets:

     ```bash
     yc vpc subnet list
     ```

     Result:

     ```text
     +----------------------+-----------+-----------------------+---------------+------------------+
     |          ID          |   NAME    |       NETWORK ID      |       ZONE    |      RANGE       |
     +----------------------+-----------+-----------------------+---------------+------------------+
     | b0cl69a2b4c6******** | default-d | enp6rq72rndgr******** | ru-central1-d | [172.**.*.*/20]  |
     | e2lkj9qwe762******** | default-b | enp6rq72rndgr******** | ru-central1-b | [10.**.*.*/16]   |
     | e9b0ph42bn96******** | a-2       | enp6rq72rndgr******** | ru-central1-a | [172.**.**.*/20] |
     | e9b9v22r88io******** | default-a | enp6rq72rndgr******** | ru-central1-a | [172.**.**.*/20] |
     +----------------------+-----------+-----------------------+---------------+------------------+
     ```

     If the required subnet is not on the list, [create it](../../vpc/operations/subnet-create.md).


  1. See the description of the CLI command for adding new hosts:

     ```bash
     yc managed-mysql host add --help
     ```

  1. Run this command (our example does not use all available parameters):

     
     ```bash
     yc managed-mysql host add \
       --cluster-name=<cluster_name> \
       --host zone-id=<availability_zone_ID>,`
         `subnet-id=<subnet_ID>,`
         `assign-public-ip=<allow_public_access_to_host>,`
         `replication-source=<source_host_name>,`
         `backup-priority=<host_backup_priority>,`
         `priority=<host_priority_for_assignment_as_master>
     ```


     Where:
     * `--cluster-name`: Managed Service for MySQL® cluster name.
     * `--host`: Host settings:
       * `zone-id`: [Availability zone](../../overview/concepts/geo-scope.md).

       
       * `subnet-id`: [Subnet ID](../../vpc/concepts/network.md#subnet). You must specify this setting if the selected availability zone has more than one subnet.
       * `assign-public-ip`: Internet access to the host, `true` or `false.`.


       * `replication-source`: [Replication](../concepts/replication.md) source for the host.
       * `backup-priority`: Host's [backup](../concepts/backup.md#size) priority, between `0` and `100`.
       * `priority`: Host priority for promotion to master if the [primary master fails](../concepts/replication.md#master-failover), between `0` and `100`.

     You can get the cluster name with the [list of clusters in the folder](cluster-list.md#list-clusters).

- Terraform {#tf}

  1. Open the current Terraform configuration file with the infrastructure plan.

     For information on how to create this file, see [Creating a cluster](cluster-create.md).
  1. Add the `host` section to the Managed Service for MySQL® cluster description:

     
     ```hcl
     resource "yandex_mdb_mysql_cluster" "<cluster_name>" {
       ...
       host {
         zone             = "<availability_zone>"
         subnet_id        = <subnet_ID>
         assign_public_ip = <allow_public_access_to_host>
         priority         = <host_priority_for_assignment_as_master>
         ...
       }
     }
     ```


     Where:

     * `assign_public_ip`: Public access to the host, `true` or `false`.
     * `priority`: Host priority for promotion to master, between `0` and `100`.

  1. Make sure the settings are correct.

     1. In the command line, navigate to the directory that contains the current Terraform configuration files defining the infrastructure.
     1. Run this command:
     
        ```bash
        terraform validate
        ```
     
        Terraform will show any errors found in your configuration files.

  1. Confirm updating the resources.

     1. Run this command to view the planned changes:
     
        ```bash
        terraform plan
        ```
     
        If you described the configuration correctly, the terminal will display a list of the resources to update and their parameters. This is a verification step that does not apply changes to your resources.
     
     1. If everything looks correct, apply the changes:
        1. Run this command:
     
           ```bash
           terraform apply
           ```
     
        1. Confirm updating the resources.
        1. Wait for the operation to complete.

  For more on the properties of the `yandex_mdb_mysql_cluster` resource, see [this provider guide](../../terraform/resources/mdb_mysql_cluster.md).

  {% note warning "Timeouts" %}
  
  The Terraform provider sets the following timeouts for Managed Service for MySQL® cluster operations:
  
  * Creating a cluster, including by restoring it from a backup: 15 minutes.
  * Updating a cluster, including the MySQL® version update: 60 minutes.
  * Deleting a cluster: 15 minutes.
  
  Operations exceeding the timeout are aborted.
  
  {% cut "How do I change these limits?" %}
  
  Add the `timeouts` section to the cluster description, such as the following:
  
  ```hcl
  resource "yandex_mdb_mysql_cluster" "<cluster_name>" {
    ...
    timeouts {
      create = "1h30m" # 1 hour 30 minutes
      update = "2h"    # 2 hours
      delete = "30m"   # 30 minutes
    }
  }
  ```
  
  {% endcut %}
  
  {% endnote %}

- REST API {#api}

  1. [Get an IAM token for API authentication](../api-ref/authentication.md) and put it into an environment variable:

      ```bash
      export IAM_TOKEN="<IAM_token>"
      ```

  1. Call the [Cluster.addHosts](../api-ref/Cluster/addHosts.md) method, e.g., via the following [cURL](https://curl.se/) request:

      
      ```bash
      curl \
          --request POST \
          --header "Authorization: Bearer $IAM_TOKEN" \
          --header "Content-Type: application/json" \
          --url 'https://mdb.api.cloud.yandex.net/managed-mysql/v1/clusters/<cluster_ID>/hosts:batchCreate' \
          --data '{
                    "hostSpecs": [
                      {
                        "zoneId": "<availability_zone>",
                        "subnetId": "<subnet_ID>",
                        "assignPublicIp": <allow_public_access_to_host>,
                        "replicationSource": "<host_FQDN>",
                        "backupPriority": "<host_backup_priority>",
                        "priority": "<host_priority_for_assignment_as_master>"
                      }
                    ]
                  }'
      ```


      Where `hostSpecs` is the array of new hosts. Each array element contains the configuration for a single host and has the following structure:

      * `zoneId`: Availability zone.

      
      * `subnetId`: Subnet ID.
      * `assignPublicIp`: Host accessibility from the internet via a public IP address, `true` or `false`.


      * `replicationSource`: Host’s replication source for [manual replication stream management](../concepts/replication.md#manual-source). Specify the [FQDN of the host](connect/fqdn.md) that will be used as the replication source.
      * `backupPriority`: Host’s [backup](../concepts/backup.md#size) priority, between `0` and `100`.
      * `priority`: Host priority for promotion to master if the [primary master fails](../concepts/replication.md#master-failover), between `0` and `100`.

      You can get the cluster ID with the [list of clusters in the folder](cluster-list.md#list-clusters).

  1. Check the [server response](../api-ref/Cluster/addHosts.md#yandex.cloud.operation.Operation) to make sure your request was successful.

- gRPC API {#grpc-api}

  1. [Get an IAM token for API authentication](../api-ref/authentication.md) and put it into an environment variable:

      ```bash
      export IAM_TOKEN="<IAM_token>"
      ```

  1. Clone the [cloudapi](https://github.com/yandex-cloud/cloudapi) repository:
     
     ```bash
     cd ~/ && git clone --depth=1 https://github.com/yandex-cloud/cloudapi
     ```
     
     Below, we assume that the repository contents reside in the `~/cloudapi/` directory.
  1. Call the [ClusterService/AddHosts](../api-ref/grpc/Cluster/addHosts.md) method, e.g., via the following [gRPCurl](https://github.com/fullstorydev/grpcurl) request:

      
      ```bash
      grpcurl \
          -format json \
          -import-path ~/cloudapi/ \
          -import-path ~/cloudapi/third_party/googleapis/ \
          -proto ~/cloudapi/yandex/cloud/mdb/mysql/v1/cluster_service.proto \
          -rpc-header "Authorization: Bearer $IAM_TOKEN" \
          -d '{
                "cluster_id": "<cluster_ID>",
                "host_specs": [
                  {
                    "zone_id": "<availability_zone>",
                    "subnet_id": "<subnet_ID>",
                    "assign_public_ip": <allow_public_access_to_host>,
                    "replication_source": "<host_FQDN>",
                    "backup_priority": "<host_backup_priority>",
                    "priority": "<host_priority_for_assignment_as_master>"
                  }
                ]
              }' \
          mdb.api.cloud.yandex.net:443 \
          yandex.cloud.mdb.mysql.v1.ClusterService.AddHosts
      ```


      Where `host_specs` is the array of new hosts. Each array element contains the configuration for a single host and has the following structure:

      * `zone_id`: Availability zone.

      
      * `subnet_id`: Subnet ID.
      * `assign_public_ip`: Internet access to the host via a public IP address, `true` or `false`.


      * `replication_source`: Host’s replication source for [manual replication stream management](../concepts/replication.md#manual-source). Specify the [FQDN of the host](connect/fqdn.md) that will be used as the replication source.
      * `backup_priority`: Host’s [backup](../concepts/backup.md#size) priority, between `0` and `100`.
      * `priority`: Host priority for promotion to master if the [primary master fails](../concepts/replication.md#master-failover), between `0` and `100`.

      You can get the cluster ID with the [list of clusters in the folder](cluster-list.md#list-clusters).

  1. Check the [server response](../api-ref/grpc/Cluster/create.md#yandex.cloud.operation.Operation) to make sure your request was successful.

{% endlist %}


{% note warning %}

If you cannot [connect](connect/index.md) to the host you added, check that the cluster [security group](../concepts/network.md#security-groups) is properly configured for the subnet containing your host.

{% endnote %}


## Updating a host {#update}

For each host in a Managed Service for MySQL® cluster, you can:
* Set the [replication source](../concepts/replication.md#manual-source).
* Manage [public access](../concepts/network.md#public-access-to-host).
* Set the backup [priority](../concepts/backup.md#size).
* Set the priority for promotion to master if the [primary master fails](../concepts/replication.md#master-failover).

{% note info %}

You cannot restart a separate cluster host. To restart hosts, [stop and restart the cluster](cluster-stop.md).

{% endnote %}

{% list tabs group=instructions %}

- Management console {#console}

  To change the cluster host settings:
  1. Navigate to **Managed Service for&nbsp;MySQL**.
  1. Click the name of your cluster and select the **Hosts** tab.
  1. Find the host you need in the list, click ![image](../../_assets/console-icons/ellipsis.svg) in its row, and select **Edit**.
  1. Specify new host settings:
     1. Select the host’s replication source for manual replication stream management.

     
     1. Enable **Public access** to make the host accessible from outside of Yandex Cloud.


     1. Set the **Master priority** field.
     1. Set the **Backup priority** field.
  1. Click **Save**.

- CLI {#cli}

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

  The folder used by default is the one specified when [creating](../../cli/operations/profile/profile-create.md) the CLI profile. To change the default folder, use the `yc config set folder-id <folder_ID>` command. You can also specify a different folder for any command using `--folder-name` or `--folder-id`. If you access a resource by its name, the search will be limited to the default folder. If you access a resource by its ID, the search will be global, i.e., through all folders based on access permissions.

  To update host settings, run the command below (our example does not use all available settings):

  
  ```bash
  yc managed-mysql host update <host_name> \
    --cluster-name=<cluster_name> \
    --replication-source=<source_host_name> \
    --assign-public-ip=<allow_public_access_to_host> \
    --backup-priority=<host_backup_priority> \
    --priority=<host_priority_for_assignment_as_master>
  ```


  Where:
  * `--cluster-name`: Managed Service for MySQL® cluster name.
  * `--replication-source`: [Replication](../concepts/replication.md) source for the host.

  
  * `--assign-public-ip`: Internet access to the host, `true` or `false`.


  * `--backup-priority`: Host’s [backup](../concepts/backup.md#size) priority, between `0` and `100`.
  * `--priority`: Host priority for promotion to master if the [primary master fails](../concepts/replication.md#master-failover), between `0` and `100`.

  You can get the host name with the [list of cluster hosts](#list), and the cluster name, with the [list of clusters in the folder](cluster-list.md#list-clusters).

- Terraform {#tf}

  To change the cluster host settings:
  1. Open the current Terraform configuration file with the infrastructure plan.

     For information on how to create this file, see [Creating a cluster](cluster-create.md).
  1. In the Managed Service for MySQL® cluster description, change the attributes of the `host` section referring to the host you want to update.

     
     ```hcl
     resource "yandex_mdb_mysql_cluster" "<cluster_name>" {
       ...
       host {
         replication_source_name = "<replication_source>"
         assign_public_ip        = <allow_public_access_to_host>
         priority                = <host_priority_for_assignment_as_master>
       }
     }
     ```


     Where:

     * `assign_public_ip`: Public access to the host, `true` or `false`.
     * `priority`: Host priority for promotion to master, between `0` and `100`.

  1. Make sure the settings are correct.

     1. In the command line, navigate to the directory that contains the current Terraform configuration files defining the infrastructure.
     1. Run this command:
     
        ```bash
        terraform validate
        ```
     
        Terraform will show any errors found in your configuration files.

  1. Confirm updating the resources.

     1. Run this command to view the planned changes:
     
        ```bash
        terraform plan
        ```
     
        If you described the configuration correctly, the terminal will display a list of the resources to update and their parameters. This is a verification step that does not apply changes to your resources.
     
     1. If everything looks correct, apply the changes:
        1. Run this command:
     
           ```bash
           terraform apply
           ```
     
        1. Confirm updating the resources.
        1. Wait for the operation to complete.

  For more on the properties of the `yandex_mdb_mysql_cluster` resource, see [this provider guide](../../terraform/resources/mdb_mysql_cluster.md).

  {% note warning "Timeouts" %}
  
  The Terraform provider sets the following timeouts for Managed Service for MySQL® cluster operations:
  
  * Creating a cluster, including by restoring it from a backup: 15 minutes.
  * Updating a cluster, including the MySQL® version update: 60 minutes.
  * Deleting a cluster: 15 minutes.
  
  Operations exceeding the timeout are aborted.
  
  {% cut "How do I change these limits?" %}
  
  Add the `timeouts` section to the cluster description, such as the following:
  
  ```hcl
  resource "yandex_mdb_mysql_cluster" "<cluster_name>" {
    ...
    timeouts {
      create = "1h30m" # 1 hour 30 minutes
      update = "2h"    # 2 hours
      delete = "30m"   # 30 minutes
    }
  }
  ```
  
  {% endcut %}
  
  {% endnote %}

- REST API {#api}

  1. [Get an IAM token for API authentication](../api-ref/authentication.md) and put it into an environment variable:

      ```bash
      export IAM_TOKEN="<IAM_token>"
      ```

  1. Call the [Cluster.updateHosts](../api-ref/Cluster/updateHosts.md) method, e.g., via the following [cURL](https://curl.se/) request:

      
      ```bash
      curl \
          --request POST \
          --header "Authorization: Bearer $IAM_TOKEN" \
          --header "Content-Type: application/json" \
          --url 'https://mdb.api.cloud.yandex.net/managed-mysql/v1/clusters/<cluster_ID>/hosts:batchUpdate' \
          --data '{
                    "updateHostSpecs": [
                      {
                        "updateMask": "assignPublicIp,replicationSource,backupPriority,priority",
                        "hostName": "<host_FQDN>",
                        "assignPublicIp": <allow_public_access_to_host>,
                        "replicationSource": "<host_FQDN>",
                        "backupPriority": "<host_backup_priority>",
                        "priority": "<host_priority_for_assignment_as_master>"
                      }
                    ]
                  }'
      ```


      Where `updateHostSpecs` is the array of hosts you are updating. Each array element contains the configuration for a single host and has the following structure:

      * `updateMask`: Comma-separated string of settings to update.
      * `hostName`: [FQDN of the host being updated](connect/fqdn.md).

      
      * `assignPublicIp`: Internet access to the host via a public IP address, `true` or `false`.


      * `replicationSource`: Host’s replication source for [manual replication stream management](../concepts/replication.md#manual-source). Specify the [FQDN of the host](connect/fqdn.md) that will be used as the replication source.
      * `backupPriority`: Host’s [backup](../concepts/backup.md#size) priority, between `0` and `100`.
      * `priority`: Host priority for promotion to master if the [primary master fails](../concepts/replication.md#master-failover), between `0` and `100`.

      You can get the cluster ID with the [list of clusters in the folder](cluster-list.md#list-clusters).

  1. Check the [server response](../api-ref/Cluster/updateHosts.md#yandex.cloud.operation.Operation) to make sure your request was successful.

- gRPC API {#grpc-api}

  1. [Get an IAM token for API authentication](../api-ref/authentication.md) and put it into an environment variable:

      ```bash
      export IAM_TOKEN="<IAM_token>"
      ```

  1. Clone the [cloudapi](https://github.com/yandex-cloud/cloudapi) repository:
     
     ```bash
     cd ~/ && git clone --depth=1 https://github.com/yandex-cloud/cloudapi
     ```
     
     Below, we assume that the repository contents reside in the `~/cloudapi/` directory.
  1. Call the [ClusterService/UpdateHosts](../api-ref/grpc/Cluster/updateHosts.md) method, e.g., via the following [gRPCurl](https://github.com/fullstorydev/grpcurl) request:

      
      ```bash
      grpcurl \
          -format json \
          -import-path ~/cloudapi/ \
          -import-path ~/cloudapi/third_party/googleapis/ \
          -proto ~/cloudapi/yandex/cloud/mdb/mysql/v1/cluster_service.proto \
          -rpc-header "Authorization: Bearer $IAM_TOKEN" \
          -d '{
                "cluster_id": "<cluster_ID>",
                "update_host_specs": [
                  {
                    "update_mask": {
                      "paths": [
                        "assign_public_ip", "replication_source", "backup_priority", "priority"
                      ]
                    },
                    "host_name": "<host_FQDN>",
                    "assign_public_ip": <allow_public_access_to_host>,
                    "replication_source": "<host_FQDN>",
                    "backup_priority": "<host_backup_priority>",
                    "priority": "<host_priority_for_assignment_as_master>"
                  }
                ]
              }' \
          mdb.api.cloud.yandex.net:443 \
          yandex.cloud.mdb.mysql.v1.ClusterService.UpdateHosts
      ```


      Where `update_host_specs` is the array of hosts you are updating. Each array element contains the configuration for a single host and has the following structure:

      * `update_mask`: List of settings to update as an array of strings (`paths[]`).
      * `host_name`: [FQDN of the host being updated](connect/fqdn.md).

      
      * `assign_public_ip`: Internet access to the host via a public IP address, `true` or `false`.


      * `replication_source`: Host’s replication source for [manual replication stream management](../concepts/replication.md#manual-source). Specify the [FQDN of the host](connect/fqdn.md) that will be used as the replication source.
      * `backup_priority`: Host’s [backup](../concepts/backup.md#size) priority, between `0` and `100`.
      * `priority`: Host priority for promotion to master if the [primary master fails](../concepts/replication.md#master-failover), between `0` and `100`.

      You can get the cluster ID with the [list of clusters in the folder](cluster-list.md#list-clusters).

  1. Check the [server response](../api-ref/grpc/Cluster/create.md#yandex.cloud.operation.Operation) to make sure your request was successful.

{% endlist %}


{% note warning %}

If you cannot [connect](connect/index.md) to the host after the update, check that the cluster [security group](../concepts/network.md#security-groups) is properly configured for the host's subnet.

{% endnote %}


## Deleting a host {#remove}

You can delete a host from a MySQL® cluster as long as it is not the only host in the cluster. To replace the only host, first create a new host and then delete the old one.

If you are deleting the master host, Managed Service for MySQL® will automatically promote the highest priority replica to master.

{% list tabs group=instructions %}

- Management console {#console}

  1. Navigate to **Managed Service for&nbsp;MySQL**.
  1. Click the name of your cluster and select the **Hosts** tab.
  1. Click ![image](../../_assets/console-icons/ellipsis.svg) in the host's row and select **Delete**.

- CLI {#cli}

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

  The folder used by default is the one specified when [creating](../../cli/operations/profile/profile-create.md) the CLI profile. To change the default folder, use the `yc config set folder-id <folder_ID>` command. You can also specify a different folder for any command using `--folder-name` or `--folder-id`. If you access a resource by its name, the search will be limited to the default folder. If you access a resource by its ID, the search will be global, i.e., through all folders based on access permissions.

  To delete a host from a cluster, run this command:

  ```bash
  yc managed-mysql host delete <host_name> \
     --cluster-name=<cluster_name>
  ```

  You can get the host name with the [list of cluster hosts](#list), and the cluster name, with the [list of clusters in the folder](cluster-list.md#list-clusters).

- Terraform {#tf}

  1. Open the current Terraform configuration file with the infrastructure plan.

     For information on how to create this file, see [Creating a cluster](cluster-create.md).
  1. Delete the `host` section from the Managed Service for MySQL® cluster description.
  1. Make sure the settings are correct.

     1. In the command line, navigate to the directory that contains the current Terraform configuration files defining the infrastructure.
     1. Run this command:
     
        ```bash
        terraform validate
        ```
     
        Terraform will show any errors found in your configuration files.

  1. Type `yes` and press **Enter**.

     1. Run this command to view the planned changes:
     
        ```bash
        terraform plan
        ```
     
        If you described the configuration correctly, the terminal will display a list of the resources to update and their parameters. This is a verification step that does not apply changes to your resources.
     
     1. If everything looks correct, apply the changes:
        1. Run this command:
     
           ```bash
           terraform apply
           ```
     
        1. Confirm updating the resources.
        1. Wait for the operation to complete.

  For more on the properties of the `yandex_mdb_mysql_cluster` resource, see [this provider guide](../../terraform/resources/mdb_mysql_cluster.md).

  {% note warning "Timeouts" %}
  
  The Terraform provider sets the following timeouts for Managed Service for MySQL® cluster operations:
  
  * Creating a cluster, including by restoring it from a backup: 15 minutes.
  * Updating a cluster, including the MySQL® version update: 60 minutes.
  * Deleting a cluster: 15 minutes.
  
  Operations exceeding the timeout are aborted.
  
  {% cut "How do I change these limits?" %}
  
  Add the `timeouts` section to the cluster description, such as the following:
  
  ```hcl
  resource "yandex_mdb_mysql_cluster" "<cluster_name>" {
    ...
    timeouts {
      create = "1h30m" # 1 hour 30 minutes
      update = "2h"    # 2 hours
      delete = "30m"   # 30 minutes
    }
  }
  ```
  
  {% endcut %}
  
  {% endnote %}

- REST API {#api}

  1. [Get an IAM token for API authentication](../api-ref/authentication.md) and put it into an environment variable:

      ```bash
      export IAM_TOKEN="<IAM_token>"
      ```

  1. Call the [Cluster.deleteHosts](../api-ref/Cluster/deleteHosts.md) method, e.g., via the following [cURL](https://curl.se/) request:

      ```bash
      curl \
          --request POST \
          --header "Authorization: Bearer $IAM_TOKEN" \
          --header "Content-Type: application/json" \
          --url 'https://mdb.api.cloud.yandex.net/managed-mysql/v1/clusters/<cluster_ID>/hosts:batchDelete' \
          --data '{
                    "hostNames": [
                      "<host_FQDN>"
                    ]
                  }'
      ```

      Where `hostNames` is the array containing the host you want to delete.

      You can provide only one host FQDN per request. If you need to delete multiple hosts, send a separate request for each one.

      You can get the cluster ID with the [list of clusters in the folder](cluster-list.md#list-clusters).

  1. Check the [server response](../api-ref/Cluster/deleteHosts.md#yandex.cloud.operation.Operation) to make sure your request was successful.

- gRPC API {#grpc-api}

  1. [Get an IAM token for API authentication](../api-ref/authentication.md) and put it into an environment variable:

      ```bash
      export IAM_TOKEN="<IAM_token>"
      ```

  1. Clone the [cloudapi](https://github.com/yandex-cloud/cloudapi) repository:
     
     ```bash
     cd ~/ && git clone --depth=1 https://github.com/yandex-cloud/cloudapi
     ```
     
     Below, we assume that the repository contents reside in the `~/cloudapi/` directory.
  1. Call the [ClusterService/DeleteHosts](../api-ref/grpc/Cluster/deleteHosts.md) method, e.g., via the following [gRPCurl](https://github.com/fullstorydev/grpcurl) request:

      ```bash
      grpcurl \
          -format json \
          -import-path ~/cloudapi/ \
          -import-path ~/cloudapi/third_party/googleapis/ \
          -proto ~/cloudapi/yandex/cloud/mdb/mysql/v1/cluster_service.proto \
          -rpc-header "Authorization: Bearer $IAM_TOKEN" \
          -d '{
                "cluster_id": "<cluster_ID>",
                "host_names": [
                  "<host_FQDN>"
                ]
              }' \
          mdb.api.cloud.yandex.net:443 \
          yandex.cloud.mdb.mysql.v1.ClusterService.DeleteHosts
      ```

      Where `host_names` is the array containing the host you want to delete.

      You can only specify one host FQDN per request. If you need to delete multiple hosts, send a separate request for each one.

      You can get the cluster ID with the [list of clusters in the folder](cluster-list.md#list-clusters).

  1. Check the [server response](../api-ref/grpc/Cluster/create.md#yandex.cloud.operation.Operation) to make sure your request was successful.

{% endlist %}