Menu
Amazon Relational Database Service
User Guide (API Version 2014-10-31)

Migrating Data from an External MySQL Database to an Amazon Aurora DB Cluster

If your database supports the InnoDB or MyISAM tablespaces, you have these options for migrating your data to an Amazon Aurora DB cluster:

For details, see Migrating Data from an External MySQL Database to an Amazon Aurora DB Cluster.

Migrating Data from MySQL by Using an Amazon S3 Bucket

You can copy the source files from your source MySQL version 5.5 or 5.6 database to an Amazon S3 bucket, and then restore an Amazon Aurora DB cluster from those files.

This option can be considerably faster than migrating data using mysqldump, because using mysqldump replays all of the commands to recreate the schema and data from your source database in your new Amazon Aurora DB cluster. By copying your source MySQL data files, Amazon Aurora can immediately use those files as the data for DB cluster.

Note

Restoring an Amazon Aurora DB cluster from backup files in an Amazon S3 bucket is not supported for the Asia Pacific (Mumbai) region.

Amazon Aurora does not restore everything from your database. You should save the database schema and values for the following items from your source MySQL or MariaDB database and add them to your restored Amazon Aurora DB cluster after it has been created.

  • User accounts

  • Functions

  • Stored procedures

  • Time zone information. Time zone information is loaded from the local operating system of your Amazon Aurora DB cluster. For more information, see Local Time Zone for Amazon Aurora DB Clusters.

Before You Begin

Before you can copy your data to an Amazon S3 bucket and restore a DB cluster from those files, you must do the following:

  • Install Percona XtraBackup on your local server.

  • Permit Amazon Aurora to access your Amazon S3 bucket on your behalf.

Installing Percona XtraBackup

Amazon Aurora can restore a DB cluster from files that were created using Percona XtraBackup. You can install Percona XtraBackup from the Percona website at https://www.percona.com/doc/percona-xtrabackup/2.4/installation.

Required Permissions

To migrate your MySQL data to an Amazon Aurora DB cluster, several permissions are required:

  • The user that is requesting that Amazon RDS create a new cluster from an Amazon S3 bucket must have permission to list the buckets for your AWS account. You grant the user this permission using an AWS Identity and Access Management (IAM) policy.

  • Amazon RDS requires permission to act on your behalf to access the Amazon S3 bucket where you store the files used to create your Amazon Aurora DB cluster. You grant Amazon RDS the required permissions using an IAM service role.

  • The user making the request must also have permission to list the IAM roles for your AWS account.

  • If the user making the request will create the IAM service role, or will request that Amazon RDS create the IAM service role (by using the console), then the user must have permission to create an IAM role for your AWS account.

For example, the following IAM policy grants a user the minimum required permissions to use the console to both list IAM roles, create an IAM role, and list the S3 buckets for your account.

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Action": [
                "iam:ListRoles",
                "iam:CreateRole",
                "iam:CreatePolicy",
                "iam:AttachRolePolicy",
                "s3:ListBucket",
                "s3:ListObjects"
            ],
            "Resource": "*"
        }
    ]
}

Additionally, for a user to associate an IAM role with an S3 bucket, the IAM user must have the iam:PassRole permission for that IAM role. This permission allows an administrator to restrict which IAM roles a user can associate with S3 buckets.

For example, the following IAM policy allows a user to associate the role named S3Access with an S3 bucket.

{
   "Version":"2012-10-17",
   "Statement":[
      {
         "Sid":"AllowS3AccessRole",
        "Effect":"Allow",
        "Action":"iam:PassRole",
        "Resource":"arn:aws:iam::123456789012:role/S3Access"
      }
   ]
}

For more information on IAM user permissions, see Using Identity-Based Policies (IAM Policies) for Amazon RDS.

Creating the IAM Service Role

You can have the Amazon RDS Management Console create a role for you by choosing the Create a New Role option (shown later in this topic). If you select this option and specify a name for the new role, then Amazon RDS will create the IAM service role required for Amazon RDS to access your S3 bucket with the name that you supply.

As an alternative, you can manually create the role using the following procedure.

To create an IAM role for Amazon RDS to access Amazon S3

  1. Sign in to the IAM console at https://console.aws.amazon.com/iam/.

  2. In the left navigation pane, choose Roles.

  3. Choose Create New Role, specify a value for Role Name for the new role, and then choose Next Step.

  4. Under AWS Service Roles, find Amazon RDS and choose Select.

  5. Do not select a policy to attach in the Attach Policy step. Instead, choose Next Step.

  6. Review your role information, and then choose Create Role.

  7. In the list of roles, choose the name of your newly created role. Choose the Permissions tab.

  8. Choose Inline Policies. Because your new role has no policy attached, you will be prompted to create one. Click the link to create a new policy.

  9. On the Set Permissions page, choose Custom Policy and then choose Select.

  10. Type a Policy Name such as S3-bucket-policy. Add the following code for Policy Document, replacing <bucket name> with the name of the S3 bucket that you are allowing access to.

    As part of the policy document, you can also include a file name prefix. If you specify a prefix, then Amazon Aurora will create the DB cluster using the files in the S3 bucket that begin with the specified prefix. If you don't specify a prefix, then Amazon Aurora will create the DB cluster using all of the files in the S3 bucket.

    To specify a prefix, replace <prefix> following with the prefix of your file names. Include the asterisk (*) after the prefix. If you don't want to specify a prefix, specify only an asterisk.

    {
        "Version": "2012-10-17",
        "Statement": [
            {
                "Effect": "Allow",
                "Action": [
                    "s3:ListBucket",
                    "s3:GetBucketLocation"
                ],
                "Resource": [
                    "arn:aws:s3:::<bucket name>"
                ]
            },
            {
                "Effect": "Allow",
                "Action": [
                    "s3:GetObject"
                ],
                "Resource": [
                    "arn:aws:s3:::<bucket name>/<prefix>*"
                ]
            }
        ]
    }
  11. Choose Apply Policy.

Backing Up Files to be Restored as a DB Cluster

To create a backup of your MySQL database files that can be restored from S3 to create an Amazon Aurora DB cluster, use the Percona Xtrabackup utility (innobackupex) to back up your database.

For example, the following command creates a backup of a MySQL database and stores the files in the /s3-restore/backup folder.

innobackupex --user=myuser --password=<password> --no-timestamp /s3-restore/backup

If you want to compress your backup into a single file (which can be split, if needed), you can use the --stream option to save your backup in one of the following formats:

  • Gzip (.gz)

  • tar (.tar)

  • Percona xbstream (.xbstream)

For example, the following command creates a backup of your MySQL database split into multiple Gzip files.

innobackupex --user=myuser --password=<password> --stream=tar \
   /mydata/s3-restore/backup | gzip - | split -d --bytes=512000 \
   - /mydata/s3-restore/backup3/backup.tar.gz

For example, the following command creates a backup of your MySQL database split into multiple tar files.

innobackupex --user=myuser --password=<password> --stream=tar \
   /mydata/s3-restore/backup | split -d --bytes=512000 \
   - /mydata/s3-restore/backup3/backup.tar

For example, the following command creates a backup of your MySQL database split into multiple xbstream files.

innobackupex --stream=xbstream  \
   /mydata/s3-restore/backup | split -d --bytes=512000 \
   - /mydata/s3-restore/backup/backup.xbstream

Amazon S3 limits the size of a file uploaded to a bucket to 5 terabytes (TB). If the backup data for your database exceeds 5 TB, then you must use the split command to split the backup files into multiple files that are each less than 5 TB.

Amazon Aurora does not support partial backups created using Percona Xtrabackup. You cannot use the --include, --tables-file, or --databases options to create a partial backup when you backup the source files for your database.

For more information, see the The innobackupex Script.

Amazon Aurora consumes your backup files based on the file name. Be sure to name your backup files with the appropriate file extension based on the file format—for example, .xbstream for files stored using the Percona xbstream format.

Amazon Aurora consumes your backup files in alphabetical order as well as natural number order. Always use the split option when you issue the innobackupex command to ensure that your backup files are written and named in the proper order.

Copying Files to an Amazon S3 Bucket

Once you have backed up your MySQL database using the Percona Xtrabackup utility, then you can copy your backup files to an Amazon S3 bucket.

For information on creating and uploading a file to an Amazon S3 bucket, see Getting Started with Amazon Simple Storage Service in the Amazon S3 Getting Started Guide.

Restoring an Aurora DB Cluster from an Amazon S3 Bucket

You can restore your backup files from your Amazon S3 bucket to a create new Amazon Aurora DB cluster by using the Amazon RDS console.

To restore an Amazon Aurora DB cluster from files on an S3 bucket

  1. Sign in to the AWS Management Console and open the Amazon RDS console at https://console.aws.amazon.com/rds/.

  2. In the RDS Dashboard, choose Restore Aurora DB Cluster from S3.

  3. In the Specify Source Backup Details, specify the following:

    For This Option Do This

    Source Engine

    Amazon Aurora currently supports only restoring from backup files for the mysql database engine.

    Source Engine Version

    Specify the version of the MySQL database that the backup files were created from, for example 5.6.22. MySQL version 5.5 and 5.6 are supported.

    Select S3 Bucket

    Select the Amazon S3 bucket where your backup files are stored.

    S3 Bucket Prefix (Optional)

    Specify a file path prefix for the files stored in your Amazon S3 bucket. The S3 Bucket Prefix is optional. If you don't specify a prefix, then Amazon Aurora will create the DB cluster using all of the files in the root folder of the S3 bucket. If you specify a prefix, then Amazon Aurora will create the DB cluster using the files in the S3 bucket where the full path for the file begins with the specified prefix.

    Amazon Aurora does not traverse subfolders in your S3 bucket looking for backup files. Only the files from the folder identified by the S3 Bucket Prefix are used. If you store your backup files in a subfolder in your S3 bucket, then you must specify a prefix that identifies the full path to the folder where the files are stored.

    For example, if you store your backup files in a subfolder of your S3 bucket named backups, and you have multiple sets of backup files, each in its own directory (gzip_backup1, gzip_backup2, and so on), then you would specify a prefix of backups/gzip_backup1 to restore from the files in the gzip_backup1 folder.

    IAM Role

    Select the IAM role that you created to authorize Amazon Aurora to access Amazon S3 on your behalf. If you have not created an IAM role, you can choose Create a New Role to create one. For more information, see Required Permissions.

    A typical Specify Source Backup Details page looks like the following.

    Amazon Aurora Migrate from an Amazon S3 bucket
  4. Choose Next Step.

  5. On the Specify DB Details page, specify your DB cluster information. The following table shows settings for a DB instance.

    For This Option Do This

    DB Instance Class

    Select a DB instance class that defines the processing and memory requirements for each instance in the DB cluster. Aurora supports the db.r3.large, db.r3.xlarge, db.r3.2xlarge, db.r3.4xlarge, and db.r3.8xlarge DB instance classes. For more information about DB instance class options, see DB Instance Class.

    Multi-AZ Deployment

    Determine if you want to create Aurora Replicas in other Availability Zones for failover support. For more information about multiple Availability Zones, see Regions and Availability Zones.

    DB Instance Identifier

    Type a name for the primary instance in your DB cluster. This identifier will be used in the endpoint address for the primary instance of your DB cluster.

    The DB instance identifier has the following constraints:

    • It must contain from 1 to 63 alphanumeric characters or hyphens.

    • Its first character must be a letter.

    • It cannot end with a hyphen or contain two consecutive hyphens.

    • It must be unique for all DB instances per AWS account, per region.

    Master Username

    Type a name using alphanumeric characters that you will use as the master user name to log on to your DB cluster. The default privileges granted to the master user name account include: create, drop, references, event, alter, delete, index, insert, select, update, create temporary tables, lock tables, trigger, create view, show view, alter routine, create routine, execute, create user, process, show databases, grant option.

    Master Password

    Type a password that contains from 8 to 41 printable ASCII characters (excluding /,", and @) for your master user password.

    A typical Specify DB Details page looks like the following.

    Amazon Aurora Launch DB Instance Wizard DB Instance Details
  6. Confirm your master password, and then choose Next.

  7. On the Configure Advanced Settings page, you can customize additional settings for your Aurora DB cluster. The following table shows the advanced settings for a DB cluster.

    For This OptionDo This

    VPC

    Select the VPC that will host the DB cluster. Select Create a New VPC to have Amazon RDS create a VPC for you. For more information, see DB Cluster Prerequisites earlier in this topic.

    Subnet Group

    Select the DB subnet group to use for the DB cluster. Select Create a New DB Subnet Group to have Amazon RDS create a DB subnet group for you. For more information, see DB Cluster Prerequisites earlier in this topic.

    Publicly Accessible

    Select Yes to give the DB cluster a public IP address; otherwise, select No. The instances in your DB cluster can be a mix of both public and private DB instances. For more information about hiding instances from public access, see Hiding a DB Instance in a VPC from the Internet.

    Availability Zone

    Determine if you want to specify a particular Availability Zone. For more information about Availability Zones, see Regions and Availability Zones.

    VPC Security Group(s)

    Select one or more VPC security groups to secure network access to the DB cluster. Select Create a New VPC Security Group to have Amazon RDS create a VPC security group for you. For more information, see DB Cluster Prerequisites earlier in this topic.

    DB Cluster Identifier

    Type a name for your DB cluster that is unique for your account in the region you selected. This identifier will be used in the cluster endpoint address for your DB cluster. For information on the cluster endpoint, see Aurora Endpoints.

    The DB cluster identifier has the following constraints:

    • It must contain from 1 to 63 alphanumeric characters or hyphens.

    • Its first character must be a letter.

    • It cannot end with a hyphen or contain two consecutive hyphens.

    • It must be unique for all DB clusters per AWS account, per region.

    Database Name

    Type a name for your database of up to 8 alphanumeric characters. If you don't provide a name, Amazon RDS will not create a database on the DB cluster you are creating.

    Database Port

    Specify the port that applications and utilities will use to access the database. Aurora DB clusters default to the default MySQL port, 3306. The firewalls at some companies block connections to the default MySQL port. If your company firewall blocks the default port, choose another port for the new DB cluster.

    Parameter Group

    Select a parameter group. Aurora has a default parameter group you can use, or you can create your own parameter group. For more information about parameter groups, see Working with DB Parameter Groups.

    Option Group

    Select an option group. Aurora has a default option group you can use, or you can create your own option group. For more information about option groups, see Working with Option Groups.

    Enable Encryption

    Select Yes to enable encryption at rest for this DB cluster. For more information, see Encrypting Amazon RDS Resources.

    Priority

    Choose a failover priority for the instance. If you don't select a value, the default is tier-1. This priority determines the order in which Aurora Replicas are promoted when recovering from a primary instance failure. For more information, see Fault Tolerance for an Aurora DB Cluster.

    Backup Retention Period

    Select the length of time, from 1 to 35 days, that Aurora will retain backup copies of the database. Backup copies can be used for point-in-time restores (PITR) of your database, timed down to the second.

    Enable Enhanced Monitoring

    Choose Yes to enable gathering metrics in real time for the operating system that your DB cluster runs on. For more information, see Enhanced Monitoring.

    Granularity

    This option is only available if Enable Enhanced Monitoring is set to Yes. Set the interval, in seconds, between times at which metrics are collected for your DB cluster.

    Auto Minor Version Upgrade

    Select Yes if you want to enable your Aurora DB cluster to receive minor MySQL DB engine version upgrades automatically when they become available.

    The Auto Minor Version Upgrade option only applies to upgrades to MySQL minor engine versions for your Amazon Aurora DB cluster. It doesn't apply to regular patches applied to maintain system stability.

    Maintenance Window

    Select the weekly time range during which system maintenance can occur.

    A typical Configure Advanced Settings page looks like the following.

    Amazon Aurora Launch DB Instance Wizard Configure Advanced Settings
  8. Choose Launch DB Instance to launch your Aurora DB instance, and then choose Close to close the wizard.

    On the Amazon RDS console, the new DB instance appears in the list of DB instances. The DB instance has a status of creating until the DB instance is created and ready for use. When the state changes to available, you can connect to the primary instance for your DB cluster. Depending on the DB instance class and store allocated, it can take several minutes for the new instance to be available.

    To view the newly created cluster, choose the Clusters view in the Amazon RDS console. For more information, see Viewing an Amazon Aurora DB Cluster.

    Amazon Aurora DB Instances List

    Note the port and the endpoint of the cluster. Use the endpoint and port of the cluster in your JDBC and ODBC connection strings for any application that performs write or read operations.

Migrating from MySQL to Amazon Aurora by Using mysqldump

Because Amazon Aurora is a MySQL-compatible database, you can use the mysqldump utility to copy data from your MySQL or MariaDB database to an existing Amazon Aurora DB cluster. For a discussion of how to do so with MySQL databases that are very large, see Importing Data to an Amazon RDS MySQL or MariaDB DB Instance with Reduced Downtime. For MySQL databases that have smaller amounts of data, see Importing Data from a MySQL or MariaDB DB to an Amazon RDS MySQL or MariaDB DB Instance.