• Relational Database Service

rds
  1. Help Center
  2. Relational Database Service
  3. User Guide
  4. Working with RDS for MySQL
  5. Migrating MySQL Data Using mysqldump
  6. Importing Data

Importing Data

This section describes how to use an ECS or a device that can access RDS to connect to a DB instance and import the exported SQL file into RDS.

If the source database contains triggers, storage processes, functions, or event invocation, you must set log_bin_trust_function_creators to ON for the destination database before importing data.

Procedure

  1. Import metadata into RDS.

    Use the mysql tool to connect to the RDS DB instance, enter the password, and run the following command to import metadata:

    # mysql -f -h <RDS_ADDRESS> -P <DB_PORT> -u root -p < <BACKUP_DIR>/dump-defs.sql

    • RDS_ADDRESS indicates the IP address of the RDS DB instance.
    • DB_PORT indicates the RDS DB instance port.
    • BACKUP_DIR indicates the directory where dump-defs.sql is stored.

    Example:

    [root@ecs-zyc-0815-2 ~]# mysql -f -h 172.16.66.198 -P 3306 -u root -p < dump-defs.sql

    Enter the database password as prompted.

  2. Import data into RDS.

    # mysql -f -h <RDS_ADDRESS> -P <DB_PORT> -u root -p < <BACKUP_DIR>/dump-data.sql

    • RDS_ADDRESS indicates the IP address of the RDS DB instance.
    • DB_PORT indicates the RDS DB instance port.
    • BACKUP_DIR indicates the directory where dump-data.sql is stored.

    Example:

    [root@ecs-zyc-0815-2 ~]# mysql -f -h 172.16.66.198 -P 3306 -u root -p < dump-data.sql

    Enter the database password as prompted.

  3. View the import result.

    mysql> show databases;

    In this example, the database named my_db has been imported.

    mysql> show databases;
    +--------------------+
    | Database           |
    +--------------------+
    | information_schema |
    | my_db              |
    | mysql              |
    | performance_schema |
    +--------------------+
    4 rows in set (0.00 sec)