Migrating to a third-party MySQL® cluster
To migrate a database deployed in a Yandex Managed Service for MySQL® cluster to a third-party MySQL® cluster:
- Transfer data.
- Disable data writes to the source database.
- Transfer the load to a third-party cluster.
Migration across versions is supported. For example, you can move databases from MySQL® 5.7 to 8. The MySQL® major version on a third-party cluster must be the same or higher than the version in the Yandex Managed Service for MySQL® cluster.
Getting started
Create a MySQL® cluster with any suitable configuration. In which case:
-
The MySQL® version must be the same or higher than the version in the source cluster.
Transferring data with an increase in the MySQL® major version is possible, but not guaranteed. For more information, see the MySQL® documentation
.You cannot
perform migration while downgrading MySQL® version. -
SQL mode must be the same as in the source cluster.
Transferring data
-
Set up the endpoints and transfer:
ManuallyTerraform-
-
Database type:
MySQL
-
Connection settings:
Managed Service for MySQL cluster
Specify the source cluster ID.
-
-
-
Database type:
MySQL
-
Connection settings:
Custom installation
Specify the target cluster connection settings.
-
-
Create a transfer of the Snapshot and increment type that will use the created endpoints.
-
If you do not have Terraform yet, install it.
-
Get the authentication credentials. You can add them to environment variables or specify them later in the provider configuration file.
-
Configure and initialize a provider. There is no need to create a provider configuration file manually, you can download it
. -
Place the configuration file in a separate working directory and specify the parameter values. If you did not add the authentication credentials to environment variables, specify them in the configuration file.
-
Download the transfer and the data-transfer-mmy-mysql.tf
endpoint configuration file to the same working directory. -
Specify the following in the configuration file:
-
Make sure the Terraform configuration files are correct using this command:
terraform validate
If there are any errors in the configuration files, Terraform will point them out.
-
Create the required infrastructure:
-
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.
-
All the required resources will be created in the specified folder. You can check resource availability and their settings in the management console
.Once created, your transfer will be activated automatically.
-
Warning
Avoid any changes to the data schema in the source and target clusters during the transfer operation. For more information, see Working with databases during transfer.
-
-
Wait for the transfer status to change to Replicating.
-
Switch the source cluster to "read-only" mode and transfer the load to the target cluster.
-
On the transfer monitoring page, wait for the Maximum data transfer delay metric to decrease to zero. This means that all changes that occurred in the source cluster after data was copied are transferred to the target cluster.
-
Deactivate the transfer and wait for its status to change to Stopped.
For more information about transfer statuses, see Transfer lifecycle.
-
Delete the endpoints and the transfer you created:
ManuallyTerraformIf you created your endpoints and transfer manually:
If you used Terraform to create your endpoints and transfer:
-
In the command line, go to the folder that houses the current Terraform configuration file with an infrastructure plan.
-
Delete the
data-transfer-mmy-mysql.tf
configuration file. -
Make sure the Terraform configuration files are correct using this command:
terraform validate
If there are any errors in the configuration files, Terraform will point them out.
-
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.
-
All the resources described in the
data-transfer-mmy-mysql.tf
configuration file will be deleted. -
-
See also
For other migration methods, see the Yandex Managed Service for MySQL® documentation.