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, see this guide.
Getting a list of cluster hosts
- Navigate to the folder dashboard
and select Managed Service for MySQL. - Click the name of your cluster and open the Hosts tab.
If you do not have the Yandex Cloud CLI installed yet, install and initialize it.
By default, the CLI uses the folder specified when creating the profile. To change the default folder, use the yc config set folder-id <folder_ID> command. You can also set a different folder for any specific command using the --folder-name or --folder-id parameter.
To get the list of cluster hosts, run this command:
yc managed-mysql host list \
--cluster-name=<cluster_name>
Result:
+----------------------------+----------------------+---------+--------+---------------+
| 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.
-
Get an IAM token for API authentication and set it as an environment variable:
export IAM_TOKEN="<IAM_token>" -
Call the Cluster.listHosts method, e.g., via the following cURL
request: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.
-
Check the server response to make sure your request was successful.
-
Get an IAM token for API authentication and set it as an environment variable:
export IAM_TOKEN="<IAM_token>" -
Clone the cloudapi
repository:cd ~/ && git clone --depth=1 https://github.com/yandex-cloud/cloudapiBelow, we assume the repository contents are stored in the
~/cloudapi/directory. -
Call the ClusterService/ListHosts method, e.g., via the following gRPCurl
request: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.ListHostsYou can get the cluster ID with the list of clusters in the folder.
-
Check the server response to make sure your request was successful.
Adding a host
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 check the resources currently in use, open the Quotas
-
Navigate to the folder dashboard
and select Managed Service for MySQL. -
Click the name of your cluster and open the Hosts tab.
-
Click Create host.
-
Specify the following host settings:
-
Availability zone.
-
Subnet (if the required subnet is not on the list, create it).
-
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.
-
If you do not have the Yandex Cloud CLI installed yet, install and initialize it.
By default, the CLI uses the folder specified when creating the profile. To change the default folder, use the yc config set folder-id <folder_ID> command. You can also set a different folder for any specific command using the --folder-name or --folder-id parameter.
To add a host to a cluster:
-
To choose a subnet for your new host, get the list of all cluster subnets:
yc vpc subnet listResult:
+----------------------+-----------+-----------------------+---------------+------------------+ | 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.
-
See the description of the CLI command for adding a host:
yc managed-mysql host add --help -
Run this command (our example does not use all available parameters):
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_promotion_to_master>Where:
--cluster-name: Managed Service for MySQL® cluster name.--host: Host settings:zone-id: Availability zone.subnet-id: Subnet ID. Specify it if the selected availability zone has two or more subnets.assign-public-ip: Internet access to the host,trueorfalse..replication-source: Replication source for the host.backup-priority: Host's backup priority, between0and100.priority: Host priority for promotion to master if the primary master fails, between0and100.
You can get the cluster name with the list of clusters in the folder.
-
Open the current Terraform configuration file describing your infrastructure.
For more information on how to create this file, see this guide.
-
Add the
hostsection to the Managed Service for MySQL® cluster description: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_promotion_to_master> ... } }Where:
assign_public_ip: Public access to the host,trueorfalse.priority: Host priority for promotion to master, between0and100.
-
Make sure the settings are correct.
-
In the command line, navigate to the directory that contains the current Terraform configuration files defining the infrastructure.
-
Run this command:
terraform validateTerraform will show any errors found in your configuration files.
-
-
Confirm updating the resources.
-
Run this command to view the planned changes:
terraform planIf 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.
-
If everything looks correct, apply the changes:
-
Run this command:
terraform apply -
Confirm updating the resources.
-
Wait for the operation to complete.
-
-
For more information, see this Terraform provider article.
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.
How do I change these limits?
Add the timeouts section to the cluster description, such as the following:
resource "yandex_mdb_mysql_cluster" "<cluster_name>" {
...
timeouts {
create = "1h30m" # 1 hour 30 minutes
update = "2h" # 2 hours
delete = "30m" # 30 minutes
}
}
-
Get an IAM token for API authentication and set it as an environment variable:
export IAM_TOKEN="<IAM_token>" -
Call the Cluster.addHosts method, e.g., via the following cURL
request: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_promotion_to_master>" } ] }'Where
hostSpecsis 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: Internet access to the host via a public IP address,trueorfalse.replicationSource: Host’s replication source for manual replication stream management. Specify the FQDN of the host that will be used as the replication source.backupPriority: Host’s backup priority, between0and100.priority: Host priority for promotion to master if the primary master fails, between0and100.
You can get the cluster ID with the list of clusters in the folder.
-
Check the server response to make sure your request was successful.
-
Get an IAM token for API authentication and set it as an environment variable:
export IAM_TOKEN="<IAM_token>" -
Clone the cloudapi
repository:cd ~/ && git clone --depth=1 https://github.com/yandex-cloud/cloudapiBelow, we assume the repository contents are stored in the
~/cloudapi/directory. -
Call the ClusterService/AddHosts method, e.g., via the following gRPCurl
request: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_promotion_to_master>" } ] }' \ mdb.api.cloud.yandex.net:443 \ yandex.cloud.mdb.mysql.v1.ClusterService.AddHostsWhere
host_specsis 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,trueorfalse.replication_source: Host’s replication source for manual replication stream management. Specify the FQDN of the host that will be used as the replication source.backup_priority: Host’s backup priority, between0and100.priority: Host priority for promotion to master if the primary master fails, between0and100.
You can get the cluster ID with the list of clusters in the folder.
-
Check the server response to make sure your request was successful.
Warning
If you cannot connect to the host you added, check that the cluster security group is properly configured for the subnet containing your host.
Updating a host
For each host in a Managed Service for MySQL® cluster, you can:
- Set the replication source.
- Manage public access.
- Set the backup priority.
- Set the priority for promotion to master if the primary master fails.
Note
You cannot restart a separate cluster host. To restart hosts, stop and restart the cluster.
To change the cluster host settings:
- Navigate to the folder dashboard
and select Managed Service for MySQL. - Click the name of your cluster and open the Hosts tab.
- Click
in the host's row and select Edit. - Specify new host settings:
-
Select the host’s replication source for manual replication stream management.
-
Enable Public access to make the host accessible from outside Yandex Cloud, if required.
-
Set the Master priority field.
-
Set the Backup priority field.
-
- Click Save.
If you do not have the Yandex Cloud CLI installed yet, install and initialize it.
By default, the CLI uses the folder specified when creating the profile. To change the default folder, use the yc config set folder-id <folder_ID> command. You can also set a different folder for any specific command using the --folder-name or --folder-id parameter.
To update host settings, run the command below (our example does not use all available settings):
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_promotion_to_master>
Where:
--cluster-name: Managed Service for MySQL® cluster name.--replication-source: Replication source for the host.--assign-public-ip: Internet access to the host,trueorfalse.--backup-priority: Host’s backup priority, between0and100.--priority: Host priority for promotion to master if the primary master fails, between0and100.
You can get the host name with the list of cluster hosts, and the cluster name, with the list of clusters in the folder.
To change the cluster host settings:
-
Open the current Terraform configuration file describing your infrastructure.
For more information on how to create this file, see this guide.
-
In the Managed Service for MySQL® cluster description, change the attributes of the
hostsection referring to the host you want to update.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_promotion_to_master> } }Where:
assign_public_ip: Public access to the host,trueorfalse.priority: Host priority for promotion to master, between0and100.
-
Make sure the settings are correct.
-
In the command line, navigate to the directory that contains the current Terraform configuration files defining the infrastructure.
-
Run this command:
terraform validateTerraform will show any errors found in your configuration files.
-
-
Confirm updating the resources.
-
Run this command to view the planned changes:
terraform planIf 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.
-
If everything looks correct, apply the changes:
-
Run this command:
terraform apply -
Confirm updating the resources.
-
Wait for the operation to complete.
-
-
For more information, see this Terraform provider article.
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.
How do I change these limits?
Add the timeouts section to the cluster description, such as the following:
resource "yandex_mdb_mysql_cluster" "<cluster_name>" {
...
timeouts {
create = "1h30m" # 1 hour 30 minutes
update = "2h" # 2 hours
delete = "30m" # 30 minutes
}
}
-
Get an IAM token for API authentication and set it as an environment variable:
export IAM_TOKEN="<IAM_token>" -
Call the Cluster.updateHosts method, e.g., via the following cURL
request: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_promotion_to_master>" } ] }'Where
updateHostSpecsis 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 list of settings you want to update.hostName: FQDN of the host being updated.assignPublicIp: Internet access to the host via a public IP address,trueorfalse.replicationSource: Host’s replication source for manual replication stream management. Specify the FQDN of the host that will be used as the replication source.backupPriority: Host’s backup priority, between0and100.priority: Host priority for promotion to master if the primary master fails, between0and100.
You can get the cluster ID with the list of clusters in the folder.
-
Check the server response to make sure your request was successful.
-
Get an IAM token for API authentication and set it as an environment variable:
export IAM_TOKEN="<IAM_token>" -
Clone the cloudapi
repository:cd ~/ && git clone --depth=1 https://github.com/yandex-cloud/cloudapiBelow, we assume the repository contents are stored in the
~/cloudapi/directory. -
Call the ClusterService/UpdateHosts method, e.g., via the following gRPCurl
request: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_promotion_to_master>" } ] }' \ mdb.api.cloud.yandex.net:443 \ yandex.cloud.mdb.mysql.v1.ClusterService.UpdateHostsWhere
update_host_specsis 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 you want to update as an array of strings (paths[]).host_name: FQDN of the host being updated.assign_public_ip: Internet access to the host via a public IP address,trueorfalse.replication_source: Host’s replication source for manual replication stream management. Specify the FQDN of the host that will be used as the replication source.backup_priority: Host’s backup priority, between0and100.priority: Host priority for promotion to master if the primary master fails, between0and100.
You can get the cluster ID with the list of clusters in the folder.
-
Check the server response to make sure your request was successful.
Warning
If you cannot connect to the host after the update, check that the cluster security group is properly configured for the subnet containing your host.
Deleting a host
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.
- Navigate to the folder dashboard
and select Managed Service for MySQL. - Click the name of your cluster and open the Hosts tab.
- Click
in the host's row and select Delete.
If you do not have the Yandex Cloud CLI installed yet, install and initialize it.
By default, the CLI uses the folder specified when creating the profile. To change the default folder, use the yc config set folder-id <folder_ID> command. You can also set a different folder for any specific command using the --folder-name or --folder-id parameter.
To delete a host from the cluster, run this command:
yc managed-mysql host delete <host_name> \
--cluster-name=<cluster_name>
You can get the host name with the list of cluster hosts, and the cluster name, with the list of clusters in the folder.
-
Open the current Terraform configuration file describing your infrastructure.
For more information on how to create this file, see this guide.
-
Delete the
hostsection from the Managed Service for MySQL® cluster description. -
Make sure the settings are correct.
-
In the command line, navigate to the directory that contains the current Terraform configuration files defining the infrastructure.
-
Run this command:
terraform validateTerraform will show any errors found in your configuration files.
-
-
Type
yesand press Enter.-
Run this command to view the planned changes:
terraform planIf 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.
-
If everything looks correct, apply the changes:
-
Run this command:
terraform apply -
Confirm updating the resources.
-
Wait for the operation to complete.
-
-
For more information, see this Terraform provider article.
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.
How do I change these limits?
Add the timeouts section to the cluster description, such as the following:
resource "yandex_mdb_mysql_cluster" "<cluster_name>" {
...
timeouts {
create = "1h30m" # 1 hour 30 minutes
update = "2h" # 2 hours
delete = "30m" # 30 minutes
}
}
-
Get an IAM token for API authentication and set it as an environment variable:
export IAM_TOKEN="<IAM_token>" -
Call the Cluster.deleteHosts method, e.g., via the following cURL
request: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
hostNamesis 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 of them.
You can get the cluster ID with the list of clusters in the folder.
-
Check the server response to make sure your request was successful.
-
Get an IAM token for API authentication and set it as an environment variable:
export IAM_TOKEN="<IAM_token>" -
Clone the cloudapi
repository:cd ~/ && git clone --depth=1 https://github.com/yandex-cloud/cloudapiBelow, we assume the repository contents are stored in the
~/cloudapi/directory. -
Call the ClusterService/DeleteHosts method, e.g., via the following gRPCurl
request: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.DeleteHostsWhere
host_namesis 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 of them.
You can get the cluster ID with the list of clusters in the folder.
-
Check the server response to make sure your request was successful.