This topic describes how to restore the data of an ApsaraDB RDS for MySQL instance from a logical backup file to a self-managed MySQL instance by using the mysqldump plug-in of MySQL.

Prerequisites

  • The RDS instance runs one of the following MySQL versions and RDS editions:
    • MySQL 8.0 on RDS High-availability Edition (with local SSDs)
    • MySQL 5.7 on RDS High-availability Edition (with local SSDs)
    • MySQL 5.6
    • MySQL 5.5
  • A logical backup is complete on the RDS instance. For more information, see Enable automatic backups for an ApsaraDB RDS for MySQL instance.
  • Tables in the RDS instance are not encrypted by using Transparent Data Encryption (TDE). If tables are encrypted by using TDE, errors occur during the restoration process. Before you restore the data of the RDS instance from a logical backup file, you must decrypt the encrypted tables. For more information, see Decrypt a table.
Note

Runtime environment

The self-managed instance is installed in a 64-bit Linux operating system and runs the same MySQL version as the RDS instance. In this topic, Linux 7 and MySQL 5.7 are used as examples.

Procedure

  1. Visit the RDS instance list, select a region above, and click the target instance ID.
  2. In the left-side navigation pane, click Backup and Restoration.
  3. On the Data Backup tab of the page, select a time range and click OK
  4. Find the logical backup file that you want to download. Then, click Download Instance Backup in the Actions column.
    Note
  5. In the Download Instance Backup Set dialog box, click Copy icon to the right of Copy Public URL.
    Note
    • A free quota for backup downloads over the Internet is provided. If the amount of traffic that you consume to download backup files over the Internet exceeds the free quota, you are charged for the excess traffic that you consume. For more information, see Billing.
    • If your Elastic Compute Service (ECS) instance resides in the same virtual private cloud (VPC) as the RDS instance, you can use the internal URL to download the logical backup file. This download method is faster and more stable.
  6. Log on to the Linux operating system on which the self-managed instance runs. Then, run the following command to download the logical backup file:
    wget -c '<The public URL from which you can download the logical backup file>' -O <The name that you want to specify as the name of the downloaded logical backup file>.tar
    Note
    • The -c option enables the resumable download feature.
    • The -O option specifies to save the downloaded logical backup file based on the specified file name.
  7. Run the following command to decompress the downloaded logical backup file, which includes the compressed files of the default system databases and the compressed files of the databases that you created:
    tar xvf <The name of the downloaded logical backup file>.tar -C /tmp

    Example:

    tar xvf hins123456.tar -C /tmp
    Decompress the downloaded logical backup file
    Note If an error message similar to "This does not look like a tar archive" is displayed, you must check whether the file that you downloaded is a logical backup file of the RDS instance.
  8. Run the following command to decompress the compressed file of the database that you want to restore (the name of the compressed file is suffixed by .sql.gz):
    gzip -d /tmp/The name of the compressed file of the database that you want to restore

    Example:

    gzip -d /tmp/testdata_datafull_202012101615_160xxxxxx.sql.gz
    Note The .sql file that is generated during the decompression process will be imported in Step 10.
  9. Run the following commands to log on to the self-managed instance and create an empty database:
    mysql -u root -p<The password that is used to log on to the self-managed instance>
    create database <The name of the empty database>;
    exit
  10. Run the following command to import the .sql file into the empty database:
    mysql -u root -p <The name of the empty database> < /tmp/The name of the decompressed file that is generated in Step 8

    Example:

    mysql -u root -p testdb < /tmp/testdata_datafull_202012101615_160xxxxxx.sql
    Note
    • After the preceding command is successfully run, the system displays a message that prompts you to enter a password. Enter the password and press Enter.
    • If the "Can't find master key from keyring" error message is displayed, check whether the RDS instance meets all prerequisites.
  11. Log on to the empty database. Then, check for data in the database. If you can find data in the database, the data of the RDS instance is successfully restored to the self-managed instance.

FAQ

  • Why does my RDS instance not have logical backup files?

    By default, ApsaraDB RDS creates physical backups. You must manually create logical backups if required. For more information, see Enable automatic backups for an ApsaraDB RDS for MySQL instance.

  • When I download a logical backup file, why is the value in the Backup Set Restore Point column displayed as 0 for the file?

    ApsaraDB RDS for MySQL allows you to restore data to a specific point in time by using a physical backup file and a log backup file. The ApsaraDB RDS console provides the Backup Set Restore Point column. In this column, you can view the timestamp of each physical backup file. Logical backup files cannot be used to restore data to a specific point in time. The value in the Backup Set Restore Point column is 0 for all logical backup files.

  • What do I do if the "ERROR 1840 (HY000) at line 24: @@GLOBAL.GTID_PURGED can only be set when @@GLOBAL.GTID_EXECUTED is empty." error message is displayed?

    This issue occurs due to GTIDs. You can use the following methods to resolve the issue:

    • Enable the GTID feature. Then, repeat the steps in the "Procedure" section of this topic to restore the data.
    • Do not enable the GTID feature. Comment out the GTID_PURGED parameter in the .sql file that you want to import. Then, repeat the steps in the "Procedure" section of this topic to restore the data.
    • Check that the synchronous replication mode is disabled. Log on to the self-managed instance, run the reset master command, and then repeat the steps in the "Procedure" section of this topic to restore the data.
  • What do I do if the "ERROR 3546 (HY000) at line 26: @@GLOBAL.GTID_PURGED cannot be changed: the added gtid set must not overlap with @@GLOBAL.GTID_EXECUTED" error message is displayed?

    The imported .sql file contains specific GTIDs that can be found in the self-managed instance. In this case, log on to the self-managed instance, run the reset master command, and then repeat the steps in the "Procedure" section of this topic to restore the data.

    restmaster
  • After the data is restored to the self-managed instance, why is the data not automatically synchronized to the secondary instance of the self-managed instance?

    Check whether you can find the "SESSION.SQL_LOG_BIN= 0" setting at the end of the imported .sql file. If the setting is specified, the data that is restored to the self-managed instance cannot be automatically synchronized to the secondary instance of the self-managed instance.

    SQL_LOG_BIN