Migrating Data from a MySQL Database to GuassDB(for MySQL)

DRS allows you to migrate data from self-built MySQL databases on an ECS to GuassDB(for MySQL) on the current cloud. With DRS, you can migrate databases online with zero downtime and your services and databases can remain operational during migration.

This section describes how to use DRS to migrate self-built MySQL databases on an ECS to GuassDB(for MySQL) on the current cloud. The following network types are supported:

  • VPC
  • VPN and Direct Connect
  • Public network

Migration Process

Figure 1 Flowchart

Migration Suggestions (Important)

  • Database migration is closely impacted by a wide range of environmental and operational factors. To ensure the migration goes smoothly, you are advised to perform a test run before the actual migration to help you detect and resolve any potential issues in advance. Recommendations on how to minimize any potential impacts on your data base are provided in this section.
  • It is strongly recommended that you start your migration task during off-peak hours. A less active database is easier to migrate successfully. If the data is fairly static, there is less likely to be any severe performance impacts during the migration.

Notes on Migration (Important)

Before creating a migration task, read the migration notes carefully.

For details, see the Before You Start section in the Getting Started with Data Replication Service.

Preparing the Migration

  1. Permissions
    Table 1 lists the permissions required for the source and destination databases when migrating self-built MySQL databases on an ECS to GuassDB(for MySQL) on the current cloud.
    Table 1 Migration permissions

    Database

    Full Migration Permission

    Full+Incremental Migration Permission

    Source

    SELECT, SHOW VIEW, and EVENT

    SELECT, SHOW VIEW, EVENT, LOCK TABLES, REPLICATION SLAVE, and REPLICATION CLIENT

    Destination

    SELECT, CREATE, DROP, DELETE, INSERT, UPDATE, INDEX, EVENT, CREATE VIEW, CREATE ROUTINE, TRIGGER, and WITH GRANT OPTION.

    SELECT, CREATE, DROP, DELETE, INSERT, UPDATE, INDEX, EVENT, CREATE VIEW, CREATE ROUTINE, TRIGGER, and WITH GRANT OPTION.

    • Source database permissions:

      The source MySQL database account must have all the required permissions listed in Table 1. If the permissions are insufficient, create a user that has all of the permissions on the source database. Destination database permissions:

      Use the initial account of GuassDB(for MySQL).

  2. Network settings
    • Source database network settings:

      You can migrate data from self-built MySQL databases on an ECS to GuassDB(for MySQL) on the cloud through a VPC, VPN, Direct Connect connection, or public network. You are advised to migrate data through a public network, which is more convenient and cost-effective.

    • Destination database network settings:
      • If the source database attempts to access the destination database through a public network, no further configuration is required.
      • If you want to access the destination database through a VPN or Direct Connect connection, enable HUAWEI CLOUD VPN first to ensure that the source MySQL database can communicate with the destination GuassDB(for MySQL) database.
      • If the source database accesses the destination database through a VPC, the source and destination databases can be either in the same VPC or in different VPCs.
        • If the source and destination databases are in the same VPC, the networks are interconnected by default.
        • If the source and destination databases are in different VPCs, the subnets of the source and destination databases are required to be in different CIDR blocks. You need to create a VPC peering connection between the two VPCs. For details, see VPC Peering Connection Overview.
  3. Security rules
    1. Source database network settings:
      • The replication instance needs to be able to access the source MySQL instance. That means that the EIP of the replication instance must be on the whitelist of the source MySQL instance. Before configuring the network whitelist for the source database, you need to obtain the EIP of the DRS replication instance.

        After creating a replication instance on the DRS console, you can find the EIP on the Configure Source and Destination Databases page as shown in Figure 2.

        Figure 2 EIP of the replication instance

        You can also add 0.0.0.0/0 to the source database whitelist to allow any IP address to access the source database but this action may result in security risks.

      • If the migration is performed through a VPN or Direct Connect connection, add the private IP address of the DRS replication instance to the whitelist of the source database to enable the source database to communicate with the destination database.
      • In the same VPC, the source and destination databases can communicate with each other through the network by default. In different VPCs, establish a VPC peering connection between the two VPCs.

      If you do take this step, then once the migration is complete, you should delete this item from the whitelist or your system will insecure.

    2. Destination database security group settings:

      By default, the destination database and the DRS replication instance are in the same VPC and can communicate with each other. No further configuration is required.

  4. Other

    DRS supports migration of some parameters that are closely related to services and performance. For details about these parameters, see Parameters for Comparison. If you need to migrate other parameters, configure them manually based on service requirements.

Migration Procedure

  1. Create a migration task.

    1. Log in to the management console and choose Database > Data Replication Service to go to the DRS console.
    2. On the Online Migration Management page, click Create Migration Task.
    3. In this example, the source database type is Self-built databases on ECS and the destination database type is Databases on the current cloud. Then, click Next to go to the Create Replication Instance page.
      • You cannot use DRS to migrate from an on-premises database to another on-premises database.
    4. On the Create Replication Instance page, configure the task details and the replication instance, and click Next.
      Figure 3 Migration task information
      Table 2 Task information

      Parameter

      Description

      Task Name

      The task name consists of 4 to 50 characters, starts with a letter, and can contain only letters (case-insensitive), digits, hyphens (-), and underscores (_).

      Send Notifications

      If the function is enabled, DRS will send notifications to the specified recipients based on the mobile numbers and email addresses you provided. If an exception occurs during the migration, the system will send a notification to the specified recipients.

      NOTE:

      Recipients must confirm the subscription on the SMN console within 48 hours of receiving an SMS message or email. Otherwise, they cannot receive notifications from DRS.

      Synchronization Delay Threshold

      During an incremental migration, a synchronization delay indicates a time difference (in seconds) of synchronization between the source and destination database.

      If the synchronization delay exceeds the threshold you specify, DRS will send alarms to the specified recipients. The value ranges from 1 to 3,600. To avoid repeated alarms caused by the fluctuation of delay, an alarm is sent only after the delay has exceeded the threshold for six minutes.

      NOTE:
      • In the early stages of an incremental migration, there is more delay because more data is waiting to be synchronized. In this situation, no notifications will be sent.
      • Before setting the delay threshold, you need to enter the recipient's mobile number or email address.

      Description

      The description consists of a maximum of 256 characters and cannot contain the following special characters: !=<>'&"

      Figure 4 Replication instance information
      Table 3 Replication instance settings

      Parameter

      Description

      Data Flow

      To the cloud

      The destination database must be a database on the current cloud.

      Source DB Engine

      MySQL

      Destination DB Engine

      GuassDB(for MySQL) Single-AZ

      Network Type

      Public network

      The default value is Public network. Alternatively, you can select VPN or Direct Connect.

      • Public network is suitable for migrations from on-premises or external cloud databases to the destination databases bound with an EIP.
      • VPN is suitable for migrations from on-premises databases to cloud databases or between cloud databases across regions.
      • Direct Connect is suitable for migration from on-premises databases to cloud databases or between cloud databases across regions.
      • VPC is suitable for migrations of cloud databases.

      Destination DB Instance

      Select the GuassDB(for MySQL) instance you have created.

      Migration Type

      You can select Full or Full+Incremental.

      • Full
        This migration type is suitable for scenarios where a service interruption is acceptable. All objects and data in non-system databases are migrated to the destination database at one time. The objects include tables, views, and stored procedures.
        NOTE:

        If you perform a full migration, you are advised to stop operations on the source database. Otherwise, data generated in the source database during the migration will not be synchronized to the destination database.

      • Full+Incremental

        This migration type allows you to migrate data without interrupting services. After a full migration initializes the destination database, an incremental migration initiates and parses logs to ensure data consistency between the source and destination databases.

      NOTE:

      If you select the Full+Incremental migration type, data generated during the full migration will be synchronized to the destination database with zero downtime, ensuring that both the source and destination databases remain accessible.

      Tags

      This setting is optional. Adding tags helps you better identify and manage your tasks. Each task can have up to 10 tags.

      After a task is created, you can view its tag details on the Tags tab. For detailed operations, see Tag Management.

    5. On the Configure Source and Destination Databases page, wait until the replication instance is created, and then configure the source and destination database details. You are advised to click Test Connection in the Source Database and Destination Database areas to check that both the source and destination databases are connected. Then, select the check box before the agreement and click Next.
      Figure 5 Source database information
      Table 4 Source database settings

      Parameter

      Description

      IP Address or Domain Name

      The IP address or domain name of the source database.

      Port

      The port of the source database.

      Range: 1 - 65535

      Database Username

      The username for accessing the source database.

      Database Password

      The password for the database username. You can change the password if necessary. To change the password, perform the following operation after the task is created:

      If the task is in the Starting, Starting failed, Full migrating, Full migration failed, Incremental migrating, or Incremental migration failed status, in the Migration Information area on the Basic Information page, click Update Password next to the Source Database Password field. In the displayed dialog box, change the password. This action only updates DRS with the changed password.

      SSL Connection

      SSL helps you encrypt the connections between the source and destination databases. If SSL is enabled, you need to upload the SSL CA root certificate.

      NOTE:
      • The maximum size of a single certificate file that can be uploaded is 500 KB.
      • If the SSL certificate is not used, your data may be at risk.
      Figure 6 Destination database information
      Table 5 Destination database settings

      Parameter

      Description

      DB Instance Name

      By default, this parameter is set to the RDS DB instance you have selected when you create the migration task and cannot be changed.

      Database Username

      The username for accessing the destination database.

      Database Password

      The password for the database username. You can change the password if necessary. To change the password, perform the following operation after the task is created:

      If the task is in the Starting, Starting failed, Full migrating, Full migration failed, Incremental migrating, or Incremental migration failed status, in the Migration Information area on the Basic Information page, click Update Password next to the Destination Database Password field. In the displayed dialog box, change the password. This action only updates DRS with the changed password.

      Migrate Definer to User

    6. On the Set Task page, select migration objects and click Next.
      Figure 7 Set Task
      Table 6 Migration object

      Parameter

      Description

      Migrate Object

      Currently, you can only migrate self-defined objects at the view- and table-level. After migration objects are successfully migrated, they are saved in the destination database with their name changed to lowercase. If the source database is changed, click in the upper right corner before selecting migration objects to ensure that the objects to be selected are from the changed source database.

      NOTE:
      • If you choose not to migrate all of the database objects, the migration may fail because the objects, such as tables and views, in the database to be migrated may have dependencies on other objects that are not migrated. You are advised to ensure that all the referenced objects are migrated.
      • When you select an object, the spaces before and after the object name are not displayed. If there are two or more consecutive spaces in the middle of the object name, only one space is displayed.
    7. On the Check Task page, check the migration task.
      • If any check fails, review the cause and rectify the fault. After the fault is rectified, click Check Again.

        For details about how to handle check failures, see the Checking Whether the Source Database Is Connected section in the Data Replication Service User Guide.

      • If all check items are successful, click Next.
      Figure 8 Task Check

      You can proceed to the next step only when all check items are successful. If any alarms are generated, view and confirm the alarm details first before proceeding to the next step.

    8. On the Confirm Task page, specify Start Time, confirm that the configured information is correct and click Submit to submit the task.

      Set Start Time to Start upon task creation or Start at a specified time based on site requirements. The Start at a specified time option is recommended.

      The migration task may affect the performance of the source and destination databases. You are advised to start the task in off-peak hours and reserve two to three days for data verification.

    9. After the task is submitted, view and manage it on the Online Migration Management page.

  2. Query the migration progress.

    1. On the Online Migration Management page, click the target migration task name in the Task Name/ID column.
    2. On the displayed page, click Migration Progress to view the migration progress.
      • View the migration progress percentage of structures, data, and indexes.
        When a full migration is complete, the progress of each item reaches 100%. If you select the Full+Incremental migration type, an incremental migration will start after the full migration is complete. You can view the delay of the incremental migration on the Migration Progress page. If the delay is 0s, it means that the destination database is synchronized with the source database in real time.
        Figure 9 Migration progress overview

        "Delay" refers to the delay from when the transaction was submitted to the source database to when it is synchronized to the destination database and executed.

        Transactions are synchronized as follows:

        1. Data is extracted from the source database.
        2. The data is transmitted over the network.
        3. DRS parses the source logs.
        4. The transaction is executed on the destination database.

        If the delay is 0, the source database is consistent with the destination database, and no new transactions need to be synchronized. Frequent DDL operations, ultra-large transactions, and network problems may result in excessive synchronization delay. If a transaction is not submitted for a long time or DDL operations are frequently performed, the latency is high.

      • View the migration task progress. In the Migration Details area, locate the target migration object and click View Details in the Operation column to view the migration progress. After the incremental migration starts, the progress is not displayed. You can click the Migration Comparison tab to compare the data consistency.
        Figure 10 Migration progress details
      • Check the data read and write performance. Click the Monitoring Graphs to view the read and write performance. This graph shows the real-time rates of reading data from the source database and writing data to the destination database. The unit is MB/s.
        Figure 11 Performance monitoring

  3. View migration logs.

    1. On the Online Migration Management page, click the target migration task name in the Task Name/ID column.
    2. On the Migration Logs tab, view the logs of the current migration task. You can filter the logs by level.
      Figure 12 Viewing migration logs

    You can view time, levels, and descriptions of the logs.

  4. Compare migration items.

    1. On the Online Migration Management page, click the target migration task name in the Task Name/ID column.
    2. On the Migration Comparison tab, compare the source and destination databases.

      You can also select the migration task on the Online Migration Management page and click View to go to the Migration Comparison page.

      1. Check the integrity of the database object.
        Click Validate Objects. On the Object-Level Comparison tab, click Compare. Wait for a while and click , and view the comparison result of each comparison item.
        Figure 13 Comparing objects

        Locate a comparison item you want to view and click View Details in the Operation column.

      2. After the check is complete, compare the number of rows and values.
        If you only need to compare the number of rows of all migration objects, you can select a specified migration task on the Online Migration Management page and click Compare in the Operation column to create a comparison task.
        1. In the Before You Start pane, click Validate All Rows/Values.
        2. On the Create Comparison Task page, set Comparison Type, Comparison Time, and Object, and click OK to submit the comparison task.
          Figure 14 Creating a comparison task
          • Comparison Type: compares rows and values.
          • Comparison Time: You can select Start upon task creation or Start at a specified time. There is a slight difference in time between the source and destination databases during synchronization. Data inconsistency may occur. You are advised to compare migration items during off-peak hours for more accurate results.
          • Object: You can select objects to be compared based on the scenarios.

          After the comparison creation task is submitted, the Data-Level Comparison tab is displayed. Click to refresh the list and view the comparison result of the specified comparison type.

          Figure 15 Viewing the data-level comparison result

          To view the comparison details, locate the target comparison type and click View Results in the Operation column. On the displayed page, locate a pair of source and destination databases, and click View Details in the Operation column to view detailed comparison results.

          Figure 16 Viewing comparison details

          You can cancel a running task at any time and view the comparison report of a canceled comparison task.

    3. Review the cutover before service cutover.

      In the Before You Start pane, click Double Check During Cutover. In the displayed Create Comparison Task dialog box, specify Comparison Type, Comparison Time, and Object. Then, click OK.

      For details about how to view the comparison details, see 4.b.

    4. Stop the migration task.

      After the service system is successfully migrated to the destination database, stop the migration task to prevent operations in the source database from being synchronized to the destination database to overwrite the data. This operation only deletes the replication instance, and the migration task is still in the task list. You can choose whether or not to delete the task. DRS will not charge for this task after you stop it.

      Generally, ending a task can ensure the integrity of special objects (triggers and events are migrated in the final migration phase). In rare cases (for example, network errors), a task may fail to be ended. If a task fails to be stopped for multiple times, you can select Forcibly stop task to reduce the waiting time. If you forcibly stop a task, the migration task will be stopped first. Triggers and events may not be completely migrated in some cases and you need to manually migrate them.