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

# Updating MySQL® cluster settings

After creating a cluster, you can:

* [Change the host class](#change-resource-preset).
* [Change the disk type and expand the storage capacity](#change-disk-size).
* [Change MySQL® settings](#change-mysql-config).

    {% note warning %}

    You cannot change MySQL® settings using SQL commands.

    {% endnote %}

* [Configure advanced cluster settings](#change-additional-settings).
* [Manually switch the master host](#start-manual-failover).
* [Move the cluster](#move-cluster) to another folder.
* [Edit security groups](#change-sg-set).

When configuration changes in clusters with two or more hosts require a host restart, during the master upgrade, one of the replicas takes over its role. Once the upgrade is complete, the host with the highest [failover priority](../concepts/replication.md#master-failover) becomes a new master. In a cluster with multiple hosts of maximum priority, the one with the least lag behind the master will be selected.

{% note tip %}

For the master host to preserve its master role after an upgrade, set the highest failover priority for it. You can set failover priority when [creating a cluster](cluster-create.md) or [updating host settings](hosts.md#update).

{% endnote %}

Learn more about other cluster updates:

* [MySQL® version upgrade](cluster-version-update.md).
* [Migrating cluster hosts to a different availability zone](host-migration.md).


## Changing the host class {#change-resource-preset}

The choice of a [host class](../concepts/instance-types.md) in Managed Service for MySQL® clusters is limited by the CPU and RAM quotas allocated to database clusters in your cloud. To check the resources currently in use, open the [Quotas](https://console.yandex.cloud/cloud?section=quotas) page and find **Managed Databases**.

{% note info %}

Some MySQL® settings [depend on the selected host class](../concepts/settings-list.md#settings-instance-dependent).

{% endnote %}

When changing the host class:

* A single-host cluster will be unavailable for a few minutes and all database connections will be dropped.
* In a multi-host cluster, hosts will be stopped and updated one by one. When stopped, a host will be unavailable for a few minutes. During the master upgrade, one of the replicas is temporarily promoted to master. Once the upgrade is complete, the host with the highest [failover priority](../concepts/replication.md#master-failover) will become the new master.
* A cluster with local SSD storage may be unavailable for an extended period of time in case of data migration to another physical server.
* Using a [special FQDN](connect/fqdn.md#fqdn-master) does not guarantee a stable database connection: user sessions may be terminated.

We recommend changing the host class only when the cluster is idle.

{% list tabs group=instructions %}

- Management console {#console}

  1. Navigate to **Managed Service for&nbsp;MySQL**.
  1. Select your cluster and click **Edit** in the top panel.
  1. To change the MySQL® host class, select the one you need under **Host class**.
  1. Click **Save changes**.

- 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 change the host class for a cluster:

  1. See the description of the CLI command for updating a cluster:

      ```bash
      yc managed-mysql cluster update --help
      ```

  1. Get the list of available host classes (the `ZONE IDS` column lists the availability zones you can select each class in):

     
     ```bash
     yc managed-mysql resource-preset list
     ```

     Result:

     ```text
     +-----------+--------------------------------+-------+----------+
     |    ID     |            ZONE IDS            | CORES |  MEMORY  |
     +-----------+--------------------------------+-------+----------+
     | s1.micro  | ru-central1-a, ru-central1-b,  |     2 | 8.0 GB   |
     |           | ru-central1-d                  |       |          |
     | ...                                                           |
     +-----------+--------------------------------+-------+----------+
     ```


  1. Specify the relevant class in the cluster update command:

      ```bash
      yc managed-mysql cluster update <cluster_name_or_ID>
        --resource-preset <class_ID>
      ```

      Managed Service for MySQL® will start updating the host class for your cluster.

- Terraform {#tf}

  1. Open the current Terraform configuration file describing your infrastructure.

      For more on how to create this file, see [Creating a cluster](cluster-create.md).

  1. Edit the `resource_preset_id` value in the `resources` section of your Managed Service for MySQL® cluster description:

      ```hcl
      resource "yandex_mdb_mysql_cluster" "<cluster_name>" {
        ...
        resources {
          resource_preset_id = "<host_class>"
          ...
        }
      }
      ```

  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 information, see [this Terraform 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.update](../api-ref/Cluster/update.md) method, e.g., via the following [cURL](https://curl.se/) request:

      {% note warning %}
      
      The API method will assign default values to all the parameters of the object you are modifying unless you explicitly provide them in your request. To avoid this, list the settings you want to change in the `updateMask` parameter as a single comma-separated string.
      
      {% endnote %}

      ```bash
      curl \
          --request PATCH \
          --header "Authorization: Bearer $IAM_TOKEN" \
          --header "Content-Type: application/json" \
          --url 'https://mdb.api.cloud.yandex.net/managed-mysql/v1/clusters/<cluster_ID>' \
          --data '{
                    "updateMask": "configSpec.resources.resourcePresetId",
                    "configSpec": {
                      "resources": {
                        "resourcePresetId": "<host_class>"
                      }
                    }
                  }'
      ```

      Where:

      * `updateMask`: Comma-separated string of settings to update.

          Here, we provide only one setting.

      * `configSpec.resources.resourcePresetId`: New host class.

      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/update.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/Update](../api-ref/grpc/Cluster/update.md) method, e.g., via the following [gRPCurl](https://github.com/fullstorydev/grpcurl) request:

      {% note warning %}
      
      The API method will assign default values to all the parameters of the object you are modifying unless you explicitly provide them in your request. To avoid this, list the settings you want to change in the `update_mask` parameter as an array of `paths[]` strings.
      
      {% cut "Format for listing settings" %}
      
      ```yaml
      "update_mask": {
          "paths": [
              "<setting_1>",
              "<setting_2>",
              ...
              "<setting_N>"
          ]
      }
      ```
      
      {% endcut %}
      
      {% endnote %}

      ```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_mask": {
                  "paths": [
                    "config_spec.resources.resource_preset_id"
                  ]
                },
                "config_spec": {
                  "resources": {
                    "resource_preset_id": "<host_class>"
                  }
                }
              }' \
          mdb.api.cloud.yandex.net:443 \
          yandex.cloud.mdb.mysql.v1.ClusterService.Update
      ```

      Where:

      * `update_mask`: List of settings you want to update as an array of strings (`paths[]`).

          Here, we provide only one setting.

      * `config_spec.resources.resource_preset_id`: New host class.

      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/update.md#yandex.cloud.operation.Operation) to make sure your request was successful.

{% endlist %}

## Changing the disk type and expanding the storage size {#change-disk-size}

Make sure the cloud has enough quota to increase the storage size. Open the cloud's [Quotas](https://console.yandex.cloud/cloud?section=quotas) page and check the **HDD storage capacity** and **SSD storage capacity** lines under **Managed Databases** to make sure there is available quota for storage space.

{% list tabs group=instructions %}

- Management console {#console}

  To change the disk type and expand the storage size for a cluster:

  1. Navigate to **Managed Service for&nbsp;MySQL**.
  1. Select your cluster and click **Edit** in the top panel.
  1. Under **Storage size**:

      * Select the [disk type](../concepts/storage.md).
      * Specify the disk size.

  1. Click **Save changes**.

- 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 change the disk type and expand the storage size for a cluster:

  1. View the description of the CLI command for updating a cluster:

      ```bash
      yc managed-mysql cluster update --help
      ```

  1. Specify the [disk type](../concepts/storage.md) and required storage size in the cluster update command (at least as large as `disk_size` in the cluster properties):

      ```bash
      yc managed-mysql cluster update <cluster_name_or_ID> \
        --disk-type <disk_type> \
        --disk-size <storage_size_in_GB>
      ```

- Terraform {#tf}

  To change the disk type and expand the storage size for a cluster:

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

      For more on how to create this file, see [Creating a cluster](cluster-create.md).

  1. Under `resources`, change the `disk_type_id` and `disk_size` parameter values:

      ```hcl
      resource "yandex_mdb_mysql_cluster" "<cluster_name>" {
        ...
        resources {
          disk_type_id = "<disk_type>"
          disk_size    = <storage_size_in_GB>
          ...
        }
      }
      ```

  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 information, see [this Terraform 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.update](../api-ref/Cluster/update.md) method, e.g., via the following [cURL](https://curl.se/) request:

      {% note warning %}
      
      The API method will assign default values to all the parameters of the object you are modifying unless you explicitly provide them in your request. To avoid this, list the settings you want to change in the `updateMask` parameter as a single comma-separated string.
      
      {% endnote %}

      ```bash
      curl \
          --request PATCH \
          --header "Authorization: Bearer $IAM_TOKEN" \
          --header "Content-Type: application/json" \
          --url 'https://mdb.api.cloud.yandex.net/managed-mysql/v1/clusters/<cluster_ID>' \
          --data '{
                    "updateMask": "configSpec.resources.diskTypeId,configSpec.resources.diskSize",
                    "configSpec": {
                      "resources": {
                        "diskTypeId": "<disk_type>",
                        "diskSize": "<storage_size_in_bytes>"
                      }
                    }
                  }'
      ```

      Where:

      * `updateMask`: Comma-separated string of settings you want to update.

      * `configSpec.resources`: Storage settings:

          * `diskTypeId`: [Disk type](../concepts/storage.md).
          * `diskSize`: New storage size in bytes.

      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/update.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/Update](../api-ref/grpc/Cluster/update.md) method, e.g., via the following [gRPCurl](https://github.com/fullstorydev/grpcurl) request:

      {% note warning %}
      
      The API method will assign default values to all the parameters of the object you are modifying unless you explicitly provide them in your request. To avoid this, list the settings you want to change in the `update_mask` parameter as an array of `paths[]` strings.
      
      {% cut "Format for listing settings" %}
      
      ```yaml
      "update_mask": {
          "paths": [
              "<setting_1>",
              "<setting_2>",
              ...
              "<setting_N>"
          ]
      }
      ```
      
      {% endcut %}
      
      {% endnote %}

      ```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_mask": {
                  "paths": [
                    "config_spec.resources.disk_type_id",
                    "config_spec.resources.disk_size"
                  ]
                },
                "config_spec": {
                  "resources": {
                    "disk_type_id": "<disk_type>",
                    "disk_size": "<storage_size_in_bytes>"
                  }
                }
              }' \
          mdb.api.cloud.yandex.net:443 \
          yandex.cloud.mdb.mysql.v1.ClusterService.Update
      ```

      Where:

      * `update_mask`: List of settings you want to update as an array of strings (`paths[]`).

      * `config_spec.resources`: Storage settings:

          * `disk_type_id`: [Disk type](../concepts/storage.md).
          * `disk_size`: New storage size in bytes.

      You can request 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/update.md#yandex.cloud.operation.Operation) to make sure your request was successful.

{% endlist %}

## Changing MySQL® settings {#change-mysql-config}

{% note info %}

Some MySQL® settings [depend on the selected host class](../concepts/settings-list.md#settings-instance-dependent).

{% endnote %}

{% list tabs group=instructions %}

- Management console {#console}

  1. Navigate to **Managed Service for&nbsp;MySQL**.
  1. Select your cluster and click **Edit** in the top panel.
  1. Change the [MySQL® settings](../concepts/settings-list.md#dbms-cluster-settings) by clicking **Settings** under **DBMS settings**.
  1. Click **Save**.
  1. Click **Save changes**.

- 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 change the [MySQL® settings](../concepts/settings-list.md#dbms-cluster-settings):

  1. View the description of the CLI command for updating the cluster configuration:

      ```bash
      yc managed-mysql cluster update-config --help
      ```

  1. Set the parameter values as needed.

     All supported parameters are listed in the [request format for the update method](../api-ref/Cluster/update.md), in the `mysql_config_5_7` field. To specify a parameter name in the CLI call, convert its name from <q>lowerCamelCase</q> to <q>snake_case</q> format. For example, convert the `logMinDurationStatement` parameter from an API request to `log_min_duration_statement` for the CLI command:

     ```bash
     yc managed-mysql cluster update-config <cluster_name>
       --set log_min_duration_statement=100,<parameter_name>=<value>,...
     ```

     Managed Service for MySQL® will start updating the cluster settings.

- Terraform {#tf}

  1. Open the current Terraform configuration file describing your infrastructure.

      For more on how to create this file, see [Creating a cluster](cluster-create.md).

  1. In the Managed Service for MySQL® cluster description, add or update the [DBMS settings](../concepts/settings-list.md) under `mysql_config`:

      ```hcl
      resource "yandex_mdb_mysql_cluster" "<cluster_name>" {
        ...
        mysql_config = {
          <MySQL®_setting_name> = <value>
          ...
        }
      }
      ```

  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 information, see [this Terraform provider guide](../../terraform/resources/mdb_mysql_cluster.md#mysql-config).

  {% 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.update](../api-ref/Cluster/update.md) method, e.g., via the following [cURL](https://curl.se/) request:

      {% note warning %}
      
      The API method will assign default values to all the parameters of the object you are modifying unless you explicitly provide them in your request. To avoid this, list the settings you want to change in the `updateMask` parameter as a single comma-separated string.
      
      {% endnote %}

      ```bash
      curl \
          --request PATCH \
          --header "Authorization: Bearer $IAM_TOKEN" \
          --header "Content-Type: application/json" \
          --url 'https://mdb.api.cloud.yandex.net/managed-mysql/v1/clusters/<cluster_ID>' \
          --data '{
                    "updateMask": "configSpec.mysqlConfig_<MySQL®_version>",
                    "configSpec": {
                      "mysqlConfig_<MySQL®_version>": {
                        "<setting_1>": "<value_1>",
                        "<setting_2>": "<value_2>",
                        ...
                        "<setting_N>": "<value_N>"
                      }
                    }
                  }'
      ```

      Where:

      * `updateMask`: Comma-separated string of settings to update.

          Here, we provide only one setting.

      * `configSpec.mysqlConfig_<MySQL®_version>`: MySQL® settings. Specify each setting on a separate line, separated by commas.

          See the [method description](../api-ref/Cluster/update.md#yandex.cloud.mdb.mysql.v1.UpdateClusterRequest) for the list of MySQL® versions supporting this option. See [Cluster-level DBMS settings](../concepts/settings-list.md#dbms-cluster-settings) for descriptions and possible values of the settings.

      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/update.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/Update](../api-ref/grpc/Cluster/update.md) method, e.g., via the following [gRPCurl](https://github.com/fullstorydev/grpcurl) request:

      {% note warning %}
      
      The API method will assign default values to all the parameters of the object you are modifying unless you explicitly provide them in your request. To avoid this, list the settings you want to change in the `update_mask` parameter as an array of `paths[]` strings.
      
      {% cut "Format for listing settings" %}
      
      ```yaml
      "update_mask": {
          "paths": [
              "<setting_1>",
              "<setting_2>",
              ...
              "<setting_N>"
          ]
      }
      ```
      
      {% endcut %}
      
      {% endnote %}

      ```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_mask": {
                  "paths": [
                    "config_spec.mysql_config_<MySQL®_version>"
                  ]
                },
                "config_spec": {
                  "mysql_config_<MySQL®_version>": {
                    "<setting_1>": "<value_1>",
                    "<setting_2>": "<value_2>",
                    ...
                    "<setting_N>": "<value_N>"
                  }
                }
              }' \
          mdb.api.cloud.yandex.net:443 \
          yandex.cloud.mdb.mysql.v1.ClusterService.Update
      ```

      Where:

      * `update_mask`: List of settings you want to update as an array of strings (`paths[]`).

          Here, we provide only one setting.

      * `configSpec.mysqlConfig_<MySQL®_version>`: MySQL® settings. Enter each setting on a new line, separated by commas.

          See the [method description](../api-ref/Cluster/update.md#yandex.cloud.mdb.mysql.v1.UpdateClusterReques) for the list of MySQL® versions supporting this option. See [Cluster-level DBMS settings](../concepts/settings-list.md#dbms-cluster-settings) for descriptions and possible values of the settings.

      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/update.md#yandex.cloud.operation.Operation) to make sure your request was successful.

{% endlist %}

For more information on updating MySQL® settings, see [FAQ](../qa/configuring.md).

## Changing additional cluster settings {#change-additional-settings}

{% list tabs group=instructions %}

- Management console {#console}

  1. Navigate to **Managed Service for&nbsp;MySQL**.
  1. Select your cluster and click **Edit** in the top panel.


  1. Configure advanced cluster settings:

     - **Automatic increase of storage size**

       * Select **In the maintenance window when full at more than** and specify the **of the current size is full** percentage at which the storage will be expanded in the next [maintenance window](../concepts/maintenance.md#maintenance-window).
             
       * Select **Immediately when full at more than** and specify the **of the current size is full** percentage at which the storage will be expanded immediately.
       
       * In the **Maximum storage size** field, specify the maximum storage size that can be set during autoscaling.
       
       {% note warning %}
             
       * Automatic storage expansion is not supported on dedicated hosts.
       * If you have configured storage scaling during a maintenance window, set the [maintenance window](../concepts/maintenance.md#maintenance-window) schedule.
       
       {% endnote %}
       
       Learn more about storage autoscaling [here](../concepts/storage.md#disk-size-autoscaling).

     - **Backup start time (UTC)**: Time interval during which the cluster backup starts. Time is specified in 24-hour UTC format. The default time is `22:00 - 23:00` UTC.
     
     - **Retention period for automatic backups, days**
     
       Automatic backups will be stored for this many days.
     
     - **Maintenance**: [Maintenance window](../concepts/maintenance.md) settings:
     
       * To enable maintenance at any time, select **At any time** (default).
       * To specify the preferred maintenance start time, select **By schedule** and specify the day of the week and the UTC time interval. For example, you can choose a time when the cluster is least loaded.
       
       Both active and stopped clusters are subject to maintenance. Maintenance operations include DBMS updates, patches, etc.
     
     - **DataLens access**: Enables you to analyze cluster data in [Yandex DataLens](../../datalens/concepts/index.md).
       
       For more information about setting up a connection, see [Connecting to DataLens](datalens-connect.md).
     
     
     - **WebSQL access**: Enables [SQL queries](web-sql-query.md) against cluster databases from the Yandex Cloud management console using Yandex WebSQL.
     
     
     - **Yandex Query access**: Enables YQL queries against cluster databases from [Yandex Query](../../query/concepts/index.md). This feature is at the [Preview](../../overview/concepts/launch-stages.md) stage. The default value is `false`.
     
     
     - **Statistics sampling**: Enable this option to use the [Performance diagnostics](performance-diagnostics.md) tool in the cluster.
     
     - **Deletion protection**: Manages cluster protection against accidental deletion.
     
         Even with cluster deletion protection enabled, one can still delete a user or database or connect manually and delete the database contents.

- 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 change advanced cluster settings:

    1. View the description of the CLI command for updating a cluster:

        ```bash
        yc managed-mysql cluster update --help
        ```

    1. Run the following command by providing the list of settings you want to update:

        
        ```bash
        yc managed-mysql cluster update <cluster_name_or_ID> \
          --backup-window-start <backup_start_time> \
          --backup-retain-period-days=<backup_retention_period> \
          --datalens-access=<true_or_false> \
          --websql-access=<true_or_false> \
          --yandexquery-access=<true_or_false> \
          --disk-size-autoscaling disk-size-limit=<maximum_storage_size_in_GB>,`
                                 `planned-usage-threshold=<scheduled_expansion_threshold_in_percent>,`
                                 `emergency-usage-threshold=<immediate_expansion_threshold_in_percent> \
          --maintenance-window type=<maintenance_type>,`
                              `day=<day_of_week>,`
                              `hour=<hour> \
          --deletion-protection \
          --performance-diagnostics enabled=true,`
                                   `sessions-sampling-interval=<session_sampling_interval>,`
                                   `statements-sampling-interval=<statement_sampling_interval>
        ```


    You can update the following settings:

    * `--backup-window-start`: The cluster backup start time, set in UTC format `HH:MM:SS`. If the time is not set, the backup will start at 22:00 UTC.

    * `--backup-retain-period-days`: Automatic backup retention period, in days. The valid values range from `7` to `60`. The default value is `7`.

    * `--datalens-access`: Enables access to the cluster from DataLens. The default value is `false`. For more information about setting up a connection, see [Connecting to a MySQL® cluster from DataLens](datalens-connect.md).

    * `--websql-access`: Enables [SQL queries](web-sql-query.md) against cluster databases from the Yandex Cloud management console using Yandex WebSQL. The default value is `false`.

    * `--yandexquery-access`: Enables YQL queries against cluster databases from [Yandex Query](../../query/concepts/index.md). This feature is at the [Preview](../../overview/concepts/launch-stages.md) stage. The default value is `false`.


    * `--disk-size-autoscaling`: [Storage autoscaling](../concepts/storage.md#disk-size-autoscaling) settings:
      * `planned-usage-threshold`: Storage usage percentage threshold triggering a storage expansion during the next maintenance window. This is an optional setting. The default value is `0` (automatic expansion disabled).
               
        The valid values range from `0` to `100`.
    
      * `emergency-usage-threshold`: Storage usage percentage threshold triggering an immediate storage expansion. This is an optional setting. The default value is `0` (automatic expansion disabled).
               
        The valid values range from `0` to `100`. 
    
      * `disk-size-limit`: Maximum storage capacity after expansion, in GB. 
    
      {% note warning %}
      
      * Automatic storage expansion is not supported on dedicated hosts.
      * When using `planned-usage-threshold`, make sure to set the `--maintenance-window`.
            
      * If you specify both thresholds, `emergency-usage-threshold` must be greater than `planned-usage-threshold`.
    
      {% endnote %}

    * `--maintenance-window`: [Maintenance window](../concepts/maintenance.md) settings that apply to both running and stopped clusters. The `type` setting defines the maintenance type:

        * `anytime`: Any time (default).
        * `weekly`: On a schedule. For this value, also specify the following:
            * `day`: Day of week, i.e., `MON`, `TUE`, `WED`, `THU`, `FRI`, `SAT`, or `SUN`.
            * `hour`: Sequence number of UTC hour interval, from `1` to `24`.
        
              > For example, `1` stands for the interval from `00:00` to `01:00`, and `5`, from `04:00` to `05:00`.

    * `--deletion-protection`: Cluster protection from accidental deletion, `true` or `false`.

        Even with cluster deletion protection enabled, one can still delete a user or database or connect manually and delete the database contents.

    * `performance-diagnostics`: Enables statistics collection for [cluster performance diagnostics](performance-diagnostics.md). For `sessions-sampling-interval` and `statements-sampling-interval`, possible values range from `1` to `86400` seconds.

    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 more on how to create this file, see [Creating a cluster](cluster-create.md).

  1. To change the backup start time, add the `backup_window_start` section to the Managed Service for MySQL® cluster description:

      ```hcl
      resource "yandex_mdb_mysql_cluster" "<cluster_name>" {
        ...
        backup_window_start {
          hours   = <hour>
          minutes = <minute>
        }
        ...
      }
      ```

      Where:

      * `hours`: Backup start hour.
      * `minutes`: Backup start minute.

  1. To change the backup retention period, specify the `backup_retain_period_days` parameter in the cluster description:

      ```hcl
        resource "yandex_mdb_mysql_cluster" "<cluster_name>" {
          ...
          backup_retain_period_days = <backup_retention_period>
          ...
        }
      ```

      Where `backup_retain_period_days` is automatic backup retention period, in days. The valid values range from `7` to `60`. The default value is `7`.

  1. To enable [access from DataLens](datalens-connect.md) and allow [SQL queries from the management console](web-sql-query.md) using Yandex WebSQL, add the `access` section to the cluster description:
     
     ```hcl
     resource "yandex_mdb_mysql_cluster" "<cluster_name>" {
       ...
       access {
         data_lens = <true_or_false>
         web_sql   = <true_or_false>
       }
       ...
     }
     ```

  1. To configure [automatic storage expansion](../concepts/storage.md#disk-size-autoscaling), add the `disk_size_autoscaling` section to the cluster description:
     
     ```hcl
     resource "yandex_mdb_mysql_cluster" "<cluster_name>" {
       ...
       disk_size_autoscaling {
         disk_size_limit           = <maximum_storage_size_in_GB>
         emergency_usage_threshold = <threshold_for_immediate_expansion_in_percent>
         planned_usage_threshold   = <threshold_for_scheduled_expansion_in_percent>
       }
       ...
     }
     ```
     
     Where:
              
     * `disk_size_limit`: Maximum storage capacity after expansion, in GB. 
     
     * `emergency_usage_threshold`: Storage usage percentage threshold triggering an immediate storage expansion. This is an optional setting. The default value is `0` (automatic expansion disabled).
                
       The valid values range from `0` to `100`.
       
     * `planned_usage_threshold`: Storage usage percentage threshold triggering a storage expansion during the next maintenance window. This is an optional setting. The default value is `0` (automatic expansion disabled).
                
       The valid values range from `0` to `100`.
     
     {% note warning %}
       
     * Automatic storage expansion is not supported on dedicated hosts.
     
     * When using `planned_usage_threshold`, make sure to set the `maintenance_window`.
             
     * If you specify both thresholds, `emergency_usage_threshold` must be greater than `planned_usage_threshold`.
     
     {% endnote %}

  1. To set up the [maintenance window](../concepts/maintenance.md) that will also apply to stopped clusters, add the `maintenance_window` section to the cluster description:
     
     ```hcl
     resource "yandex_mdb_mysql_cluster" "<cluster_name>" {
       ...
       maintenance_window {
         type = "<maintenance_type>"
         day  = "<day_of_week>"
         hour = <hour>
       }
       ...
     }
     ```
     
     Where:
     
     * `type`: Maintenance type. The possible values include:
         * `ANYTIME`: Any time.
         * `WEEKLY`: On a schedule.
     * `day`: Day of week for the `WEEKLY` type, i.e., `MON`, `TUE`, `WED`, `THU`, `FRI`, `SAT`, or `SUN`.
     * `hour`: Sequence number of UTC hour interval for the `WEEKLY` type, from `1` to `24`.
     
       > For example, `1` stands for the interval from `00:00` to `01:00`, and `5`, from `04:00` to `05:00`.

  1. To activate cluster protection against accidental deletion by a user of your cloud, add the `deletion_protection` field set to `true` to the cluster description:

      ```hcl
      resource "yandex_mdb_mysql_cluster" "<cluster_name>" {
        ...
        deletion_protection = <protect_cluster_from_deletion>
      }
      ```

      Where `deletion_protection` is the cluster protection from accidental deletion: `true` or `false`.

      Even with cluster deletion protection enabled, one can still delete a user or database or connect manually and delete the database contents.

  1. To enable statistics collection for [cluster performance diagnostics](performance-diagnostics.md), add a `performance_diagnostics` section to your Managed Service for MySQL® cluster description:

      ```hcl
      resource "yandex_mdb_mysql_cluster" "<cluster_name>" {
        ...
        performance_diagnostics {
          enabled = true
          sessions_sampling_interval = <session_sampling_interval>
          statements_sampling_interval = <statement_sampling_interval>
        }
        ...
      }
      ```

      For `sessions_sampling_interval` and `statements_sampling_interval`, possible values range from `1` to `86400` seconds.

  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 information, see [this Terraform 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. Create a file named `body.json` and paste the following code into it:

      {% note warning %}
      
      The API method will assign default values to all the parameters of the object you are modifying unless you explicitly provide them in your request. To avoid this, list the settings you want to change in the `updateMask` parameter as a single comma-separated string.
      
      {% endnote %}

      
      ```json
      {
          "updateMask": "configSpec.backupWindowStart,configSpec.backupRetainPeriodDays,configSpec.access,configSpec.performanceDiagnostics,maintenanceWindow,deletionProtection",
          "configSpec": {
              "backupWindowStart": {
                  "hours": "<hours>",
                  "minutes": "<minutes>",
                  "seconds": "<seconds>",
                  "nanos": "<nanoseconds>"
              },
              "backupRetainPeriodDays": "<number_of_days>",
              "access": {
                  "dataLens": <allow_access_from_DataLens>,
                  "webSql": <allow_access_from_WebSQL>,
                  "yandexQuery": <allow_access_from_Yandex_Query>
              },
              "performanceDiagnostics": {
                  "enabled": <enable_statistics_collection>,
                  "sessionsSamplingInterval": "<session_sampling_interval>",
                  "statementsSamplingInterval": "<statement_sampling_interval>"
              },
              "diskSizeAutoscaling": {
                  "plannedUsageThreshold": "<scheduled_expansion_threshold_in_percent>",
                  "emergencyUsageThreshold": "<immediate_expansion_threshold_in_percent>",
                  "diskSizeLimit": "<maximum_storage_size_in_bytes>"
              }
          },
          "maintenanceWindow": {
              "weeklyMaintenanceWindow": {
                  "day": "<day_of_week>",
                  "hour": "<hour>"
              }
          },
          "deletionProtection": <protect_cluster_from_deletion>
      }
      ```


      Where:

      * `updateMask`: Comma-separated string of settings to update.
      * `configSpec`: Cluster settings:

          * `backupWindowStart`: [Backup](../concepts/backup.md) window settings.

              In this parameter, specify the backup start time:

              * `hours`: Between `0` and `23` hours.
              * `minutes`: Between `0` and `59` minutes.
              * `seconds`: Between `0` and `59` seconds.
              * `nanos`: Between `0` and `999999999` nanoseconds.

          * `backupRetainPeriodDays`: Number of days to retain the cluster backup, between `7` and `60`.

          * `access`: Settings for cluster access from Yandex Cloud services:

            * `dataLens`: Access from DataLens. For more information about setting up a connection, see [Connecting from DataLens](datalens-connect.md).
            * `webSql`: [SQL queries](web-sql-query.md) against cluster databases from the Yandex Cloud management console using Yandex WebSQL.
            * `yandexQuery`: YQL queries against cluster databases from [Yandex Query](../../query/concepts/index.md). This feature is currently at the [Preview](../../overview/concepts/launch-stages.md) stage.


            The possible values are `true` or `false`.

          * `performanceDiagnostics`: [Statistics collection](performance-diagnostics.md#activate-stats-collector) settings:

              * `enabled`: Enables statistics collection, `true` or `false`.
              * `sessionsSamplingInterval`: Session sampling interval, from `1` to `86400` seconds.
              * `statementsSamplingInterval`: Statement sampling interval, from `1` to `86400` seconds.

          * `diskSizeAutoscaling`: [Storage autoscaling](../concepts/storage.md#disk-size-autoscaling) settings:
            * `plannedUsageThreshold`: Storage usage percentage threshold triggering a storage expansion during the next maintenance window. This is an optional setting. The default value is `0` (automatic expansion disabled).
                     
              The valid values range from `0` to `100`.
          
            * `emergencyUsageThreshold`: Storage usage percentage threshold triggering an immediate storage expansion. This is an optional setting. The default value is `0` (automatic expansion disabled).
                     
              The valid values range from `0` to `100`. 
          
            * `diskSizeLimit`: Maximum storage capacity after expansion, in bytes. 
          
            {% note warning %}
            
            * Automatic storage expansion is not supported on dedicated hosts.
            * When using `plannedUsageThreshold`, make sure to set the `maintenanceWindow`.
                  
            * If you specify both thresholds, `emergencyUsageThreshold` must be greater than `plannedUsageThreshold`.
          
            {% endnote %}

      * `maintenanceWindow`: [Maintenance window](../concepts/maintenance.md) settings (including for disabled clusters). Provide one of the following:
      
        * `anytime` (default): Maintenance can take place at any time.
        * `weeklyMaintenanceWindow`: Scheduled maintenance:
      
          * `day`: Day of week, in `DDD` format. The valid values are `MON`, `TUE`, `WED`, `THU`, `FRI`, `SAT`, and `SUN`.
          * `hour`: Hour of day (UTC) in `HH` format. The valid values range from `1` to `24`.

      * `deletionProtection`: Cluster deletion protection, `true` or `false`.

          Even with cluster deletion protection enabled, one can still delete a user or database or connect manually and delete the database contents.

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

      ```bash
      curl \
          --request PATCH \
          --header "Authorization: Bearer $IAM_TOKEN" \
          --header "Content-Type: application/json" \
          --url 'https://mdb.api.cloud.yandex.net/managed-mysql/v1/clusters/<cluster_ID>' \
          --data "@body.json"
      ```

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

  1. Check the [server response](../api-ref/Cluster/update.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. Create a file named `body.json` and paste the following code into it:

      {% note warning %}
      
      The API method will assign default values to all the parameters of the object you are modifying unless you explicitly provide them in your request. To avoid this, list the settings you want to change in the `update_mask` parameter as an array of `paths[]` strings.
      
      {% cut "Format for listing settings" %}
      
      ```yaml
      "update_mask": {
          "paths": [
              "<setting_1>",
              "<setting_2>",
              ...
              "<setting_N>"
          ]
      }
      ```
      
      {% endcut %}
      
      {% endnote %}

      
      ```json
      {
          "cluster_id": "<cluster_ID>",
          "update_mask": {
              "paths": [
                  "config_spec.backup_window_start",
                  "config_spec.backup_retain_period_days",
                  "config_spec.access",
                  "config_spec.performance_diagnostics",
                  "maintenance_window",
                  "deletion_protection"
              ]
          },
          "config_spec": {
              "backup_window_start": {
                  "hours": "<hours>",
                  "minutes": "<minutes>",
                  "seconds": "<seconds>",
                  "nanos": "<nanoseconds>"
              },
              "backup_retain_period_days": "<number_of_days>",
              "access": {
                  "data_lens": <allow_access_from_DataLens>,
                  "web_sql": <allow_access_from_WebSQL>,
                  "yandex_query": <allow_access_from_Yandex_Query>
              },
              "performance_diagnostics": {
                  "enabled": <enable_statistics_collection>,
                  "sessions_sampling_interval": "<session_sampling_interval>",
                  "statements_sampling_interval": "<statement_sampling_interval>"
              },
              "disk_size_autoscaling": {
                  "planned_usage_threshold": "<scheduled_expansion_threshold_in_percent>",
                  "emergency_usage_threshold": "<immediate_expansion_threshold_in_percent>",
                  "disk_size_limit": "<maximum_storage_size_in_bytes>"
              }
          },
          "maintenance_window": {
              "weekly_maintenance_window": {
                  "day": "<day_of_week>",
                  "hour": "<hour>"
              }
          },
          "deletion_protection": <protect_cluster_from_deletion>
      }
      ```


      Where:

      * `update_mask`: List of settings to update as an array of strings (`paths[]`).
      * `config_spec`: Cluster settings:

          * `backup_window_start`: [Backup](../concepts/backup.md) window settings.

              Here, specify the backup start time:

              * `hours`: Between `0` and `23` hours.
              * `minutes`: Between `0` and `59` minutes.
              * `seconds`: Between `0` and `59` seconds.
              * `nanos`: Between `0` and `999999999` nanoseconds.

          * `backup_retain_period_days`: Number of days to retain the cluster backup, between `7` and `60`.

          * `access`: Settings for cluster access from Yandex Cloud services:

              * `data_lens`: Access from DataLens. For more information about setting up a connection, see [Connecting from DataLens](datalens-connect.md).
              * `web_sql`: [SQL queries](web-sql-query.md) against cluster databases from the Yandex Cloud management console using Yandex WebSQL.
              * `yandex_query`: YQL queries against cluster databases from [Yandex Query](../../query/concepts/index.md). This feature is currently at the [Preview](../../overview/concepts/launch-stages.md) stage.


              The possible values are `true` or `false`.

          * `performance_diagnostics`: [Statistics collection](performance-diagnostics.md#activate-stats-collector) settings:

              * `enabled`: Enables statistics collection, `true` or `false`.
              * `sessions_sampling_interval`: Session sampling interval, from `1` to `86400` seconds.
              * `statements_sampling_interval`: Statement sampling interval, from `1` to `86400` seconds.

          * `disk_size_autoscaling`: [Storage autoscaling](../concepts/storage.md#disk-size-autoscaling) settings:
                   
            * `planned_usage_threshold`: Storage usage percentage threshold triggering a storage expansion during the next maintenance window. This is an optional setting. The default value is `0` (automatic expansion disabled).
                     
              The valid values range from `0` to `100`.
          
            * `emergency_usage_threshold`: Storage usage percentage threshold triggering an immediate storage expansion. This is an optional setting. The default value is `0` (automatic expansion disabled).
                     
              The valid values range from `0` to `100`.
          
            * `disk_size_limit`: Maximum storage capacity after expansion, in bytes. 
          
            {% note warning %}
            
            * Automatic storage expansion is not supported on dedicated hosts.
            * When using `planned_usage_threshold`, make sure to set the `maintenance_window`.
                  
            * If you specify both thresholds, `emergency_usage_threshold` must be greater than `planned_usage_threshold`.
          
            {% endnote %}

      * `maintenance_window`: [Maintenance window](../concepts/maintenance.md) settings (including for disabled clusters). Provide one of the following:
      
        * `anytime` (default): Maintenance can take place at any time.
        * `weekly_maintenance_window`: Scheduled maintenance:
      
          * `day`: Day of week, in `DDD` format. The valid values are `MON`, `TUE`, `WED`, `THU`, `FRI`, `SAT`, and `SUN`.
          * `hour`: Hour of day (UTC) in `HH` format. The valid values range from `1` to `24`.

      * `deletion_protection`: Cluster deletion protection, `true` or `false`.

          Even with cluster deletion protection enabled, one can still delete a user or database or connect manually and delete the database contents.

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

  1. Call the [ClusterService/Update](../api-ref/grpc/Cluster/update.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 @ \
          mdb.api.cloud.yandex.net:443 \
          yandex.cloud.mdb.mysql.v1.ClusterService.Update \
          < body.json
      ```

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

{% endlist %}


### Connection Manager {#conn-man}

If you cluster has no integration with Connection Manager, enable **Use Connection Manager**. You can only do it in the [management console](https://console.yandex.cloud).

The following resources will be created for each database user:

* Connection Manager [connection](../../metadata-hub/concepts/connection-manager.md) containing database connection details.

* [Yandex Lockbox secret](../../metadata-hub/concepts/secret.md) containing the user password. Yandex Lockbox provides secure storage for passwords.

  The connection and secret will be created for each new database user. To view all connections, open the **Connections** tab on the cluster page.

  You need the `connection-manager.viewer` role to view the connection details. You can [use Connection Manager to configure access to connections](../../metadata-hub/operations/connection-access.md).

  {% note info %}

  Connection Manager and any secrets created with it are free of charge.

  {% endnote %}


## Manually switching the master host {#start-manual-failover}

In a [highly available Managed Service for MySQL® cluster](../concepts/high-availability.md) with multiple hosts, you can perform a failover to switch the master role from the current master host to one of its replicas. After the failover, the current master host becomes a replica for the new master.

Consider these key points when performing a failover in Managed Service for MySQL®:

* You cannot promote a cascading replica to master.
* If you do not explicitly specify the replica host name, the master will switch to the replica with the highest priority or the lowest lag.

To learn more, see [Replication](../concepts/replication.md).

To perform a master failover:

{% 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 ![icon-hosts.svg](../../_assets/console-icons/cube.svg) **Hosts** tab.
  1. Click ![icon-autofailover.svg](../../_assets/console-icons/shuffle.svg) **Switch master**.
      * To switch the master to one of the replicas, leave the **Choose master host automatically** option enabled.
      * To switch the master to a specific replica, disable the **Choose master host automatically** option and then select the replica from the drop-down list.
  1. Click **Switch**.

- 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.

  Run this command:

  ```bash
  yc managed-mysql cluster start-failover <cluster_name_or_ID> \
      --host <replica_host_name>
  ```

  You can get the replica host name with the [list of cluster hosts](hosts.md#list), and 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.StartFailover](../api-ref/Cluster/startFailover.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>:startFailover' \
       --data '{
                 "hostName": "<host_FQDN>"
               }'
     ```

     Where `hostName` is the [FQDN of the replica](connect/fqdn.md) promoted to master.

     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/startFailover.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.StartFailover](../api-ref/grpc/Cluster/startFailover.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_name": "<host_FQDN>"
           }' \
       mdb.api.cloud.yandex.net:443 \
       yandex.cloud.mdb.mysql.v1.ClusterService.StartFailover
     ```

     Where `host_name` is the [FQDN of the replica](connect/fqdn.md) which becomes the master host.

     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/startFailover.md#yandex.cloud.operation.Operation) to make sure your request was successful.

{% endlist %}

## Moving a cluster {#move-cluster}

{% list tabs group=instructions %}

- Management console {#console}

    1. Navigate to **Managed Service for&nbsp;MySQL**.
    1. Click ![image](../../_assets/console-icons/ellipsis.svg) next to the cluster you want to move.
    1. Select **Move**.
    1. Select the destination folder for your cluster.
    1. Click **Move**.

- 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 move a cluster:

    1. See the description of the CLI command for moving a cluster:

        ```bash
        yc managed-mysql cluster move --help
        ```

    1. Specify the destination folder in the cluster move command:

        ```bash
        yc managed-mysql cluster move <cluster_ID> \
           --destination-folder-name=<destination_folder_name>
        ```

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

- Terraform {#tf}

    1. Open the current Terraform configuration file describing your infrastructure.

        For more on how to create this file, see [Creating a cluster](cluster-create.md).

    1. In the Managed Service for MySQL® cluster description, add or update the `folder_id` argument:

        ```hcl
        resource "yandex_mdb_mysql_cluster" "<cluster_name>" {
          ...
          folder_id = "<destination_folder_ID>"
        }
        ```

    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 information, see [this Terraform 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.move](../api-ref/Cluster/move.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>:move' \
          --data '{
                    "destinationFolderId": "<folder_ID>"
                  }'
      ```

      Where `destinationFolderId` is the ID of the target folder for your cluster. You can get it from the [list of your cloud folders](../../resource-manager/operations/folder/get-id.md)

      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/move.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/Move](../api-ref/grpc/Cluster/move.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>",
                "destination_folder_id": "<folder_ID>"
              }' \
          mdb.api.cloud.yandex.net:443 \
          yandex.cloud.mdb.mysql.v1.ClusterService.Move
      ```

      Where `destination_folder_id` is the ID of the folder to which you are moving your cluster. You can get it from the [list of your cloud folders](../../resource-manager/operations/folder/get-id.md)

      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/move.md#yandex.cloud.operation.Operation) to make sure your request was successful.

{% endlist %}


## Updating security groups {#change-sg-set}

{% list tabs group=instructions %}

- Management console {#console}

    1. Navigate to **Managed Service for&nbsp;MySQL**.
    1. Select your cluster and click **Edit** in the top panel.
    1. Under **Network settings**, select the security groups for cluster network traffic.

- 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 change the list of [security groups](../concepts/network.md#security-groups) for your cluster:

    1. View the description of the CLI command for updating a cluster:

        ```bash
        yc managed-mysql cluster update --help
        ```

    1. Specify the security groups in the cluster update command:

        ```bash
        yc managed-mysql cluster update <cluster_name_or_ID> \
          --security-group-ids <list_of_security_group_IDs>
        ```

- Terraform {#tf}

  1. Open the current Terraform configuration file describing your infrastructure.

      For more on how to create this file, see [Creating a cluster](cluster-create.md).

  1. Edit the `security_group_ids` parameter in the Managed Service for MySQL® cluster description:

      ```hcl
      resource "yandex_mdb_mysql_cluster" "<cluster_name>" {
        ...
        security_group_ids = [<list_of_security_group_IDs>]
      }
      ```

  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 information, see [this Terraform 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.update](../api-ref/Cluster/update.md) method, e.g., via the following [cURL](https://curl.se/) request:

      {% note warning %}
      
      The API method will assign default values to all the parameters of the object you are modifying unless you explicitly provide them in your request. To avoid this, list the settings you want to change in the `updateMask` parameter as a single comma-separated string.
      
      {% endnote %}

      ```bash
      curl \
          --request PATCH \
          --header "Authorization: Bearer $IAM_TOKEN" \
          --header "Content-Type: application/json" \
          --url 'https://mdb.api.cloud.yandex.net/managed-mysql/v1/clusters/<cluster_ID>' \
          --data '{
                    "updateMask": "securityGroupIds",
                      "securityGroupIds": [
                        "<security_group_1_ID>",
                        "<security_group_2_ID>",
                        ...
                        "<security_group_N_ID>"
                      ]
                  }'
      ```

      Where:

      * `updateMask`: Comma-separated string of settings to update.

          Here, we provide only one setting.

      * `securityGroupIds`: New [security groups](../concepts/network.md#security-groups), formatted as an array.

      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/update.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/Update](../api-ref/grpc/Cluster/update.md) method, e.g., via the following [gRPCurl](https://github.com/fullstorydev/grpcurl) request:

      {% note warning %}
      
      The API method will assign default values to all the parameters of the object you are modifying unless you explicitly provide them in your request. To avoid this, list the settings you want to change in the `update_mask` parameter as an array of `paths[]` strings.
      
      {% cut "Format for listing settings" %}
      
      ```yaml
      "update_mask": {
          "paths": [
              "<setting_1>",
              "<setting_2>",
              ...
              "<setting_N>"
          ]
      }
      ```
      
      {% endcut %}
      
      {% endnote %}

      ```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_mask": {
                  "paths": [
                    "security_group_ids"
                  ]
                },
                "security_group_ids": [
                  "<security_group_1_ID>",
                  "<security_group_2_ID>",
                  ...
                  "<security_group_N_ID>"
                ]
              }' \
          mdb.api.cloud.yandex.net:443 \
          yandex.cloud.mdb.mysql.v1.ClusterService.Update
      ```

      Where:

      * `update_mask`: List of settings you want to update as an array of strings (`paths[]`).

          Here, we provide only one setting.

      * `security_group_ids`: New [security groups](../concepts/network.md#security-groups), formatted as an array.

      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/update.md#yandex.cloud.operation.Operation) to make sure your request was successful.

{% endlist %}

{% note warning %}

You may need to [configure security groups](connect/index.md#configure-security-groups) to enable access to your cluster.

{% endnote %}