Managing MySQL® cluster hosts
You can add and remove cluster hosts and manage their settings. For information about moving cluster hosts to a different availability zone, see this guide.
Getting a list of cluster hosts
- Go to the folder page
and select Managed Service for MySQL. - Click the name of the cluster you need and select the Hosts tab.
If you do not have the Yandex Cloud command line interface yet, install and initialize it.
The folder specified in the CLI profile is used by default. You can specify a different folder using the --folder-name
or --folder-id
parameter.
To get a list of cluster hosts, run the 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 request the cluster name with a list of clusters in the folder.
-
Get an IAM token for API authentication and put it into the environment variable:
export IAM_TOKEN="<IAM_token>"
-
Use the Cluster.listHosts method and make a request, e.g., via cURL
: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 a list of clusters in the folder.
-
View the server response to make sure the request was successful.
-
Get an IAM token for API authentication and put it into the environment variable:
export IAM_TOKEN="<IAM_token>"
-
Clone the cloudapi
repository:cd ~/ && git clone --depth=1 https://github.com/yandex-cloud/cloudapi
Below, we assume the repository contents are stored in the
~/cloudapi/
directory. -
Use the ClusterService/ListHosts call and make a request, e.g., via gRPCurl
:grpcurl \ -format json \ -import-path ~/cloudapi/ \ -import-path ~/cloudapi/third_party/googleapis/ \ -proto ~/cloudapi/yandex/cloud/mdb/mysql/v1/cluster_service.proto \ -rpc-header "Authorization: Bearer $IAM_TOKEN" \ -d '{ "cluster_id": "<cluster_ID>" }' \ mdb.api.cloud.yandex.net:443 \ yandex.cloud.mdb.mysql.v1.ClusterService.ListHosts
You can get the cluster ID with a list of clusters in the folder.
-
View the server response to make sure the request was successful.
Adding a host
The number of hosts in Managed Service for MySQL® clusters is limited by the CPU and RAM quotas available to DB clusters in your cloud. To check the resources currently in use, open the Quotas
-
Go to the folder page
and select Managed Service for MySQL. -
Click the cluster name and go to the Hosts tab.
-
Click Create host.
-
Specify the host parameters:
-
Availability zone.
-
Subnet (if the required subnet is not on the list, create it).
-
Select Public access if the host must be accessible from outside Yandex Cloud.
-
Priority for assigning the host as a master.
-
Host priority as a MySQL® replica for creating backups.
-
If you do not have the Yandex Cloud command line interface yet, install and initialize it.
The folder specified in the CLI profile is used by default. You can specify a different folder using the --folder-name
or --folder-id
parameter.
To add a host to a cluster:
-
Request a list of cluster subnets to select one for the new host:
yc vpc subnet list
Result:
+----------------------+-----------+-----------------------+---------------+------------------+ | 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 in the list, create it.
-
View a description of the CLI command for adding a host:
yc managed-mysql host add --help
-
Run the add host command (the example does not show all the available parameters):
yc managed-mysql host add \ --cluster-name=<cluster_name> \ --host zone-id=<availability_zone_ID>,` `subnet-id=<subnet_ID>,` `assign-public-ip=<public_access_to_subcluster_host>,` `replication-source=<source_host_name>,` `backup-priority=<host_backup_priority>,` `priority=<priority_for_assigning_host_as_master>
Where:
--cluster-name
: Managed Service for MySQL® cluster name.--host
: Host parameters:zone-id
: Availability zone.subnet-id
: Subnet ID. Specify if two or more subnets are created in the selected availability zone.assign-public-ip
: Host accessibility from the internet,true
orfalse.
.replication-source
: Replication source for the host.backup-priority
: Host's backup priority, between0
and100
.priority
: Priority for assigning the host as master if the primary master fails, between0
and100
.
You can request the cluster name with a list of clusters in the folder.
-
Open the current Terraform configuration file with an infrastructure plan.
For more information about creating this file, see Creating clusters.
-
Add a
host
block 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 = <public_access_to_host> priority = <priority_for_assigning_host_as_master> ... } }
Where:
assign_public_ip
: Public access to the host,true
orfalse
.priority
: Priority of assigning the host as master, between0
and100
.
-
Make sure the settings are correct.
-
Using the command line, navigate to the folder that contains the up-to-date Terraform configuration files with an infrastructure plan.
-
Run the command:
terraform validate
If there are errors in the configuration files, Terraform will point to them.
-
-
Confirm updating the resources.
-
Run the command to view planned changes:
terraform plan
If the resource configuration descriptions are correct, the terminal will display a list of the resources to modify and their parameters. This is a test step. No resources are updated.
-
If you are happy with the planned changes, apply them:
-
Run the command:
terraform apply
-
Confirm the update of resources.
-
Wait for the operation to complete.
-
-
For more information, see the Terraform provider documentation
Time limits
A Terraform provider sets the timeout for Managed Service for MySQL® cluster operations:
- Creating a cluster, including by restoring one from a backup: 15 minutes.
- Editing a cluster, including the MySQL® version update: 60 minutes.
- Deleting a cluster: 15 minutes.
Operations exceeding the set timeout are interrupted.
How do I change these limits?
Add the timeouts
block to the cluster description, for example:
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 put it into the environment variable:
export IAM_TOKEN="<IAM_token>"
-
Use the Cluster.addHosts method and make a request, e.g., via cURL
: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": <public_host_address:_true_or_false>, "replicationSource": "<host_FQDN>", "backupPriority": "<host_backup_priority>", "priority": "<priority_for_assigning_host_as_master>" } ] }'
Where
hostSpecs
is an array of new hosts. One array element contains settings 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.replicationSource
: Replication source for the host to manually manage replication threads. In the parameter, specify the FQDN of the host to be used as a replication source.backupPriority
: Host's backup priority, between0
and100
.priority
: Priority for assigning the host as master if the primary master fails, between0
and100
.
You can get the cluster ID with a list of clusters in the folder.
-
View the server response to make sure the request was successful.
-
Get an IAM token for API authentication and put it into the environment variable:
export IAM_TOKEN="<IAM_token>"
-
Clone the cloudapi
repository:cd ~/ && git clone --depth=1 https://github.com/yandex-cloud/cloudapi
Below, we assume the repository contents are stored in the
~/cloudapi/
directory. -
Use the ClusterService/AddHosts call and make a request, e.g., via gRPCurl
: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": <public_host_address:_true_or_false>, "replication_source": "<host_FQDN>", "backup_priority": "<host_backup_priority>", "priority": "<priority_for_assigning_host_as_master>" } ] }' \ mdb.api.cloud.yandex.net:443 \ yandex.cloud.mdb.mysql.v1.ClusterService.AddHosts
Where
host_specs
is an array of new hosts. One array element contains settings 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.replication_source
: Replication source for the host to manually manage replication threads. In the parameter, specify the FQDN of the host to be used as a replication source.backup_priority
: Host's backup priority, between0
and100
.priority
: Priority for assigning the host as master if the primary master fails, between0
and100
.
You can get the cluster ID with a list of clusters in the folder.
-
View the server response to make sure the request was successful.
Warning
If you cannot connect to the host you added, check that the cluster security group is configured correctly for the host's subnet.
Changing a host
For each host in a Managed Service for MySQL® cluster, you can:
- Setting the replication source.
- Managing public access.
- Setting backup priority.
- Set a priority for assigning the host as a 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 parameters of the cluster host:
- Go to the folder page
and select Managed Service for MySQL. - Click the cluster name and open the Hosts tab.
- Click
in the host row and select Edit. - Set new settings for the host:
- Select a replication source for the host to control replication threads manually.
- Enable Public access if the host must be accessible from outside Yandex Cloud.
- Set the value of the Master priority field.
- Set the value of the Backup priority field.
- Click Save.
If you do not have the Yandex Cloud command line interface yet, install and initialize it.
The folder specified in the CLI profile is used by default. You can specify a different folder using the --folder-name
or --folder-id
parameter.
To modify host parameters, execute the command below (the parameter list in the example is not exhaustive):
yc managed-mysql host update <host_name> \
--cluster-name=<cluster_name> \
--replication-source=<source_host_name> \
--assign-public-ip=<public_access_to_host> \
--backup-priority=<host_backup_priority> \
--priority=<priority_for_assigning_host_as_master>
Where:
--cluster-name
: Managed Service for MySQL® cluster name.--replication-source
: Replication source for the host.--assign-public-ip
: Host accessibility from the internet,true
orfalse
.--backup-priority
: Host's backup priority, between0
and100
.--priority
: Priority for assigning the host as master if the primary master fails, between0
and100
.
You can request the host name with a list of cluster hosts, and the cluster name, with a list of clusters in the folder.
To change the parameters of the cluster host:
-
Open the current Terraform configuration file with an infrastructure plan.
For more information about creating this file, see Creating clusters.
-
In the Managed Service for MySQL® cluster description, change the attributes of the
host
block corresponding to the host you are updating.resource "yandex_mdb_mysql_cluster" "<cluster_name>" { ... host { replication_source_name = "<replication_source>" assign_public_ip = <public_access_to_host> priority = <priority_for_assigning_host_as_master> } }
Where:
assign_public_ip
: Public access to the host,true
orfalse
.priority
: Priority of assigning the host as master, between0
and100
.
-
Make sure the settings are correct.
-
Using the command line, navigate to the folder that contains the up-to-date Terraform configuration files with an infrastructure plan.
-
Run the command:
terraform validate
If there are errors in the configuration files, Terraform will point to them.
-
-
Confirm updating the resources.
-
Run the command to view planned changes:
terraform plan
If the resource configuration descriptions are correct, the terminal will display a list of the resources to modify and their parameters. This is a test step. No resources are updated.
-
If you are happy with the planned changes, apply them:
-
Run the command:
terraform apply
-
Confirm the update of resources.
-
Wait for the operation to complete.
-
-
For more information, see the Terraform provider documentation
Time limits
A Terraform provider sets the timeout for Managed Service for MySQL® cluster operations:
- Creating a cluster, including by restoring one from a backup: 15 minutes.
- Editing a cluster, including the MySQL® version update: 60 minutes.
- Deleting a cluster: 15 minutes.
Operations exceeding the set timeout are interrupted.
How do I change these limits?
Add the timeouts
block to the cluster description, for example:
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 put it into the environment variable:
export IAM_TOKEN="<IAM_token>"
-
Use the Cluster.updateHosts method and make a request, e.g., via cURL
: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": <public_host_address:_true_or_false>, "replicationSource": "<host_FQDN>", "backupPriority": "<host_backup_priority>", "priority": "<priority_for_assigning_host_as_master>" } ] }'
Where
updateHostSpecs
is an array of hosts being changed. One array element contains settings for a single host and has the following structure:updateMask
: List of parameters to update as a single string, separated by commas.hostName
: FQDN of the host being changed.assignPublicIp
: Internet access to the host via a public IP address.replicationSource
: Replication source for the host to manually manage replication threads. In the parameter, specify the FQDN of the host to be used as a replication source.backupPriority
: Host's backup priority, between0
and100
.priority
: Priority for assigning the host as master if the primary master fails, between0
and100
.
You can get the cluster ID with a list of clusters in the folder.
-
View the server response to make sure the request was successful.
-
Get an IAM token for API authentication and put it into the environment variable:
export IAM_TOKEN="<IAM_token>"
-
Clone the cloudapi
repository:cd ~/ && git clone --depth=1 https://github.com/yandex-cloud/cloudapi
Below, we assume the repository contents are stored in the
~/cloudapi/
directory. -
Use the ClusterService/UpdateHosts call and make a request, e.g., via gRPCurl
: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": <public_host_address:_true_or_false>, "replication_source": "<host_FQDN>", "backup_priority": "<host_backup_priority>", "priority": "<priority_for_assigning_host_as_master>" } ] }' \ mdb.api.cloud.yandex.net:443 \ yandex.cloud.mdb.mysql.v1.ClusterService.UpdateHosts
Where
update_host_specs
is an array of hosts being changed. One array element contains settings for a single host and has the following structure:update_mask
: List of parameters to update as an array ofpaths[]
strings.host_name
: FQDN of the host being changed.assign_public_ip
: Internet access to the host via a public IP address.replication_source
: Replication source for the host to manually manage replication threads. In the parameter, specify the FQDN of the host to be used as a replication source.backup_priority
: Host's backup priority, between0
and100
.priority
: Priority for assigning the host as master if the primary master fails, between0
and100
.
You can get the cluster ID with a list of clusters in the folder.
-
View the server response to make sure the request was successful.
Warning
If you cannot connect to the host after you changed it, check that the cluster security group is configured correctly for the host's subnet.
Removing a host
You can remove a host from a MySQL® cluster if it is not the only host in it. To replace a single host, first create a new host and then remove the old one.
If the host is the master when deleted, Managed Service for MySQL® automatically assigns the replica of the next highest priority as the master.
- Go to the folder page
and select Managed Service for MySQL. - Click the cluster name and open the Hosts tab.
- Click
in the host row and select Delete.
If you do not have the Yandex Cloud command line interface yet, install and initialize it.
The folder specified in the CLI profile is used by default. You can specify a different folder using the --folder-name
or --folder-id
parameter.
To remove a host from the cluster, run:
yc managed-mysql host delete <host_name> \
--cluster-name=<cluster_name>
You can request the host name with a list of cluster hosts, and the cluster name, with a list of clusters in the folder.
-
Open the current Terraform configuration file with an infrastructure plan.
For more information about creating this file, see Creating clusters.
-
Delete the
host
block from the Managed Service for MySQL® cluster description. -
Make sure the settings are correct.
-
Using the command line, navigate to the folder that contains the up-to-date Terraform configuration files with an infrastructure plan.
-
Run the command:
terraform validate
If there are errors in the configuration files, Terraform will point to them.
-
-
Type
yes
and press Enter.-
Run the command to view planned changes:
terraform plan
If the resource configuration descriptions are correct, the terminal will display a list of the resources to modify and their parameters. This is a test step. No resources are updated.
-
If you are happy with the planned changes, apply them:
-
Run the command:
terraform apply
-
Confirm the update of resources.
-
Wait for the operation to complete.
-
-
For more information, see the Terraform provider documentation
Time limits
A Terraform provider sets the timeout for Managed Service for MySQL® cluster operations:
- Creating a cluster, including by restoring one from a backup: 15 minutes.
- Editing a cluster, including the MySQL® version update: 60 minutes.
- Deleting a cluster: 15 minutes.
Operations exceeding the set timeout are interrupted.
How do I change these limits?
Add the timeouts
block to the cluster description, for example:
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 put it into the environment variable:
export IAM_TOKEN="<IAM_token>"
-
Use the Cluster.deleteHosts method and make a request, e.g., via cURL
:curl \ --request POST \ --header "Authorization: Bearer $IAM_TOKEN" \ --header "Content-Type: application/json" \ --url 'https://mdb.api.cloud.yandex.net/managed-mysql/v1/clusters/<cluster_ID>/hosts:batchDelete' \ --data '{ "hostNames": [ "<host_FQDN>" ] }'
Where
hostNames
is an array with the host to delete.Only one host FQDN can be provided in a single request. If you need to delete multiple hosts, run the request for each of them.
You can get the cluster ID with a list of clusters in the folder.
-
View the server response to make sure the request was successful.
-
Get an IAM token for API authentication and put it into the environment variable:
export IAM_TOKEN="<IAM_token>"
-
Clone the cloudapi
repository:cd ~/ && git clone --depth=1 https://github.com/yandex-cloud/cloudapi
Below, we assume the repository contents are stored in the
~/cloudapi/
directory. -
Use the ClusterService/DeleteHosts call and make a request, e.g., via gRPCurl
:grpcurl \ -format json \ -import-path ~/cloudapi/ \ -import-path ~/cloudapi/third_party/googleapis/ \ -proto ~/cloudapi/yandex/cloud/mdb/mysql/v1/cluster_service.proto \ -rpc-header "Authorization: Bearer $IAM_TOKEN" \ -d '{ "cluster_id": "<cluster_ID>", "host_names": [ "<host_FQDN>" ] }' \ mdb.api.cloud.yandex.net:443 \ yandex.cloud.mdb.mysql.v1.ClusterService.DeleteHosts
Where
host_names
is an array with the host to delete.Only one host FQDN can be provided in a single request. If you need to delete multiple hosts, run the request for each of them.
You can get the cluster ID with a list of clusters in the folder.
-
View the server response to make sure the request was successful.