Migrating a MySQL-Compatible Database to Amazon Aurora MySQL
If your database supports the InnoDB or MyISAM tablespaces, you have these options for migrating your data to an Amazon Aurora MySQL DB cluster:
-
You can create a dump of your data using the
mysqldump
utility, and then import that data into an existing Amazon Aurora MySQL DB cluster. For more information, see Migrating MySQL to Amazon Aurora MySQL by Using mysqldump. -
You can copy the source files from your database to an Amazon S3 bucket, and then restore an Amazon Aurora MySQL DB cluster from those files. This option can be considerably faster than migrating data using
mysqldump
. For more information, see Migrating Data from an External MySQL Database to an Amazon Aurora MySQL Using Amazon S3.
Migrating Data from an External MySQL Database to an Amazon Aurora MySQL Using Amazon S3
You can copy the source files from your source MySQL version 5.5, 5.6, or 5.7 database to an Amazon S3 bucket, and then restore an Amazon Aurora MySQL 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 MySQL DB cluster. By copying your source MySQL data files, Amazon Aurora MySQL can immediately use those files as the data for DB cluster.
Note
Restoring an Amazon Aurora MySQL DB cluster from backup files in an Amazon S3 bucket is not supported for the Asia Pacific (Mumbai) region.
Amazon Aurora MySQL 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 MySQL 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 MySQL DB cluster.
Prerequisites
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 MySQL to access your Amazon S3 bucket on your behalf.
Installing Percona XtraBackup
Amazon Aurora MySQL 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/software/mysql-database/percona-xtrabackup
Required Permissions
To migrate your MySQL data to an Amazon Aurora MySQL 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 user. You grant the user this permission using an Amazon 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 MySQL 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 user.
-
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 user.
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 user.
{ "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" } ] }
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 Amazon S3 bucket with the name that you supply.
As an alternative, you can manually create the role using the following procedure.
-
Sign in to the Amazon Web Services Management Console and open the IAM console at https://console.aws.amazon.com/iam/
. -
In the left navigation pane, choose Roles.
-
Choose Create New Role, specify a value for Role Name for the new role, and then choose Next Step.
-
Under Amazon Service Roles, find Amazon RDS and choose Select.
-
Do not select a policy to attach in the Attach Policy step. Instead, choose Next Step.
-
Review your role information, and then choose Create Role.
-
In the list of roles, choose the name of your newly created role. Choose the Permissions tab.
-
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.
-
On the Set Permissions page, choose Custom Policy and then choose Select.
-
Enter 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 MySQL 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 MySQL 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>*" ] } ] }
-
Choose Apply Policy.
Step 1: 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 MySQL 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. The parameter values shown are for a small test database; for your scenario, you should determine the parameter values needed.
innobackupex --user=myuser --password=<password> --stream=tar \ /mydata/s3-restore/backup | 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 MySQL 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 innobackupex Script
Amazon Aurora MySQL 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, 0—xbstream
for files stored using the Percona xbstream format.
Amazon Aurora MySQL 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.
Step 2: 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 about creating and uploading a file to an Amazon S3 bucket, see Getting Started with Amazon Simple Storage Service
Step 3: Restoring an Aurora MySQL DB Cluster from an Amazon S3 Bucket
You can restore your backup files from your Amazon S3 bucket to a create new Amazon Aurora MySQL DB cluster by using the Amazon RDS console.
-
Sign in to the Amazon Web Services Management Console and open the Amazon RDS console at https://console.aws.amazon.com/rds/
. -
In the RDS Dashboard, choose Restore Aurora MySQL DB Cluster from S3.
-
In the Create database by restoring from S3 page, specify the following settings in the following sections:
-
In the S3 Destination section, specify the following:
Parameter Action S3 Bucket
Select the Amazon S3 bucket where your backup files are stored.
S3 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 MySQL 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 MySQL 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 MySQL 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 ofbackups/gzip_backup1
to restore from the files in thegzip_backup1
folder. -
In the Engine Options section, specify the following:
Parameter Action Engine Type
Keep Amazon Aurora selected.
Edition
Keep Amazon Aurora with MySQL compatibility selected.
Version
Specify the version of the MySQL database that the backup files were created from, for example
5.7
. MySQL version 5.6 and 5.7 are supported. -
In the IAM role section, specify the following:
Parameter Action IAM Role
Choose the IAM role that you created to authorize Amazon Aurora MySQL 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.
-
In the Settings section, specify the following:
Parameter Action DB cluster identifier
Enter a name for 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 user, for each region.
Master Username
Enter 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
.Auto generate a password
Leave unchecked.
Master Password
Enter a password that contains from 8 to 41 printable ASCII characters (excluding /,", and @) for your master user password.
Confirm Password
Retype the Master Password.
-
-
In the DB Instance Class section, specify the following:
Parameter Action DB Instance Class
Select a DB instance class that defines the processing and memory requirements for each instance in the DB cluster. Aurora MySQL supports the
db.r3.large
,db.r3.xlarge
,db.r3.2xlarge
,db.r3.4xlarge
, anddb.r3.8xlarge
DB instance classes. For more information about DB instance class options, see the Amazon RDS documentation.. -
In the Availability & durability section, specify the following:
Parameter Action Multi-AZ Deployment
Determine if you want to create Aurora MySQL Replicas in other Availability Zones for failover support. For more information about multiple Availability Zones, see the Amazon RDS documentation
. -
In the Connectivity section, specify the following:
Parameter Action Virtual private cloud (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 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 earlier in this topic.
Public access
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 the Amazon RDS documentation
. 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 earlier in this topic.
Availability Zone
Determine if you want to specify a particular Availability Zone. For more information about Availability Zones, see the Amazon RDS documentation
. Database Port
Specify the port that applications and utilities will use to access the database. Aurora MySQL 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.
-
In the Database authentication section, specify the following:
Parameter Action Database Authentication
Leave Password authentication selected.
-
In the Additional configuration section, specify the following:
Parameter Action Initial Database Name
Enter 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.
DB cluster parameter Group
Select a parameter group for the cluster. Aurora MySQL has a default parameter group you can use, or you can create your own parameter group. For more information about parameter groups, see the Amazon RDS documentation
. DB parameter Group
Select a parameter group for the database.
Option Group
Select an option group. Aurora MySQL has a default option group you can use, or you can create your own option group. For more information about option groups, see the Amazon RDS documentation
. Failover 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 MySQL Replicas are promoted when recovering from a primary instance failure. For more information, see Amazon RDS documentation
. Backup Retention Period
Select the length of time, from 1 to 35 days, that Aurora MySQL 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.
Copy tags to snapshots
Leave checked.
Enable Encryption
Check the box to enable encryption at rest for this DB cluster. Leave Amazon KMS Key set to (default) aws/rds. For more information, see Amazon RDS documentation
. Backtrack
Leave unchecked.
Enable Performance insights
Leave checked. Leave Retention Period and Amazon KMS Key as they are.
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 Amazon RDS documentation
. 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.
Monitoring role
Leave as default.
Log exports
Leave unchecked.
Enable auto Minor Version Upgrade
Check this box if you want to enable your Aurora MySQL 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 MySQL 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.
Enable deletion protection
Leave unchecked.
-
-
Choose Launch DB Instance to launch your Aurora MySQL 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 Amazon RDS documentation
. 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 MySQL to Amazon Aurora MySQL by Using mysqldump
You can create a dump of your data using the mysqldump
utility, and then import that data into an existing Amazon Aurora MySQL DB cluster.
Because Amazon Aurora MySQL 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 MySQL DB cluster.