• Loading Your Data
  • Data Sources
  • MySQL

MySQL

This page covers how to use a MySQL table as a data source in Rockset.

These step-by-step instructions will allow you to migrate your data from your MySQL database table(s) into Rockset collection(s) by using AWS’s Data Migration Service (DMS) to export your data to a target AWS Kinesis stream. Those Rockset collection(s) will stay in sync with your MySQL databases table(s) as they are updated in real-time by reading MySQL CDC streams. This includes:

  • Setting up your MySQL Server
  • Setting up a target AWS Kinesis Stream
  • Setting up an AWS DMS Replication Instance and Migration Task
  • Creating an Amazon Kinesis integration

These instructions will work with all of the following MySQL and MySQL-compatible databases:

  • On-Premise MySQL (versions 5.6, 5.7, and 8.0)
  • On-Premise MariaDB (versions 10.0.24 to 10.0.28, 10.1, 10.2, 10.3, 10.4, and 10.5)
  • Amazon RDS MySQL (versions 5.6, 5.7, and 8.0)
  • Amazon RDS MariaDB (versions 10.0.24 to 10.0.28, 10.1, 10.2, 10.3, 10.4, and 10.5)
  • Amazon Aurora MySQL (all versions)

#Step 1: MySQL Server Configuration

#Step 1.1 - Create a MySQL user to allow DMS to access your data

In order for DMS to export your data (both the initial export and when reading CDC streams), you will need to create a new MySQL user with read access to your MySQL data. Depending on what MySQL database you are using, you may have several options for completing this task – in this example, we will use the MySQL Command-Line Client, for a user named aws-dms:

mysql> CREATE USER 'aws-dms' IDENTIFIED BY 'password';
mysql> GRANT SELECT ON *.* TO 'aws-dms';
mysql> GRANT REPLICATION SLAVE ON *.* TO  'aws-dms';
mysql> GRANT REPLICATION CLIENT ON *.* TO  'aws-dms';

#Step 1.2 - Configure your MySQL server to emit a CDC stream

The MySQL server emits binlogs which form the basis of the CDC stream. A MySQL server’s configuration is encapsulated in the form of a Parameter-Group. You have to first enable MySQL binlogs to be exposed in the row format by updating the binlog_format parameter, if not yet set, in the corresponding Parameter-Group. The value of this parameter should be set to ROW.

Use the AWS Console to access your MySQL database instance. With each database, you access the associated Parameter Group as shown below:

custom-parameter-group

If your MySQL server is using the default Parameter Group, then you will not be able to change that specific parameter in that Parameter Group because the default Parameter Group is read-only. In that case, create a new Parameter Group and then update the binlog_format as shown below:

binlog-format

#Step 1.3 - Enable Periodic Backups of MySQL

MySQL binlogs are enabled only if you enable the Periodic Backup feature of MySQL. Select the MySQL instance in the AWS Console and navigate to the “Maintenance and Backups" tab. If automatic backups are not enabled, modify the MySQL instance to enable the feature. After you are done, the ‘Maintenance and Backups` tab should look something like this:

periodic-backup

#Step 2: Create an AWS Kinesis Stream

The AWS Kinesis Stream is the destination that DMS uses as the target of a migration job. We will create an individual migration task for each MySQL table you wish to connect with Rockset. Use the AWS Console as shown below to create an AWS Kinesis Data Stream.

A separate Kinesis Data Stream is required for every database table you wish to connect with Rockset.

Create an AWS Kinesis Stream here.

kinesis-stream

You can increase the number of configured shards based on the size of your MySQL database table and the update rate on that database table at any point. However, reducing the number of shards is not supported at the moment. If you are not able to estimate the number of shards to configure here, please contact your Rockset solutions architect or customer support.

#Step 3: Setup your AWS Data Migration (DMS)

AWS DMS setup is a multi-step process. First, you have to create one or more DMS Replication Instances. Each Replication Instance comes with a set of resources that power the data migration from MySQL to Kinesis. Then you will create a DMS Source Endpoint for each MySQL server. You will then create one DMS Destination Endpoint for each of the MySQL database table that you want to connect with Rockset. The Source Endpoint is used to configure the name of the MySQL server and the Destination Endpoint specifies the name of the corresponding Kinesis stream. Finally, you will configure a Database Migration Task that specifies the MySQL table names that you want to connect with Rockset. The creation of a Database Migration Task actually starts the migration of data from a specific MySQL table to the corresponding Kinesis stream.

#Step 3.1 Create a DMS Replication Instance

AWS DMS uses a replication instance to connect to your source data store, read the source data, and format the data for consumption by the target data store. A replication instance also loads the data into the target data store. Most of this processing happens in memory; however, large transactions might require some buffering on disk. Cached transactions and log files are also written to disk. You can create a Replication Instance by using the AWS Console as follows:

replication-instance

The Instance class specifies the amount of resources provisioned for this Replication Instance. You can pick the Instance class based on the total amount of data to be migrated and how quickly you want the replication process to occur. You can pick the default or the most recent version of the DMS Replication Instance. Name the Replication Instance appropriately, especially if you are creating multiple Replication Instances.

#Step 3.2 Create a DMS Source Endpoint for your MySQL server

A Source Endpoint specifies the location and access information of your MySQL server. You use the AWS Console to create a DMS Source Endpoint as follows:

  • Pick the RDS instance name for the MySQL server.
  • Pick an appropriate name for this Endpoint. You can specify access parameters by clicking on “Provide access information manually", and entering the name server name and port of the MySQL server. You can use the MySQL user aws-dms and password that you had created in Step 1.1.

source-endpoint

If you want multiple MySQL database tables in a single MySQL server to be connected to Rockset, you only need to create a single Source Endpoint for that server. The same Source Endpoint can then be used by multiple Migration Tasks in a later step. You can click on the “Test endpoint connection (optional)” tab to verify that the access configurations to access the MySQL server are configured correctly.

#Step 3.3 Create a DMS Target Endpoint for every MySQL database table

The DMS Target Endpoint specifies the name of the Kinesis Stream that is the target of a migration task. Create a DMS Target Endpoint as follows:

target-endpoint

Pick Amazon Kinesis as the Target Engine. Enter the ARN of the Kinesis Stream created in Step 2 in the field named “Kinesis Stream ARN”. Additionally, enter a Service access role ARN of a role that has full read permissions to access Kinesis. If you do not have any such Role already created, please use the IAM section of the AWS Console to create such a Role.

You can click on the “Test endpoint connection (optional)” tab to verify that the access configurations to access the Kinesis Stream service are configured correctly.

#Step 3.4 Create a DMS Database Migration Task to migrate a MySQL table to a Kinesis Stream

A Migration Task connects one specific MySQL database table on a specific MySQL server to a specific Kinesis Stream. Use the AWS Console to specify the following:

migration-task-1

Pick the option for Migration type as “Migrate existing data and replicate ongoing changes”. This option does a full dump of the MySQL database table to Kinesis first, followed by continuous replication through MySQL CDC using the same Kinesis Stream. Specify the following task settings:

task-settings

Configure these values as required if you are working with a large table. Their default values are 0.

"ParallelLoadThreads": 32,
"ParallelLoadBufferSize": 1000,
"BatchApplyEnabled": true,
"ParallelApplyThreads": 32,
"ParallelApplyBufferSize": 1000,
"ParallelApplyQueuesPerThread": 1,

The name of the MySQL table that you want to migrate is specified in the section titled Table Mappings. Here is an exmaple where a table named customers in a database named rockset is being configured:

table-mappings-1

You can switch on Pre-migration assessment to verify that the settings are accurate. If you switch on the assessment then remember to manally start the task once the pre-migration assessment is complete.

Now that you have completed steps 1-3, you are ready to create the Rockset Kinesis integration.

#Creating a Rockset Collection

  1. Go to collection creation and select the MySQL tile under Managed Integrations. This will guide you through a series of steps to follow to set up the Kinesis Intergration needed to create the collection.

collection-creation-1

  1. Populate the fields as shown below. Note that Format must be set to MYSQL. Also, it is mandatory to specify an immutable primary key from the source MySQL table during collection creation.

collection-creation-2

#Field Mapping Complex Types

Following is a table of custom field mappings that you can apply to a field to ingest it in the desired type.

MySQL Data TypeSupported By DMSRockset Data TypeRockset Field Mapping
INTYintNone
BIGINTYintNone
MEDIUMINTYintNone
TINYINTYintNone
DECIMAL(p,s)YfloatNone
BINARYYbytesFROM_HEX(SUBSTR(binary_column, 3))
BIT(M)YbytesFROM_HEX(SUBSTR(bit_column, 3))
BLOBYbytesFROM_HEX(SUBSTR(blob_column, 3))
LONGBLOBYbytesFROM_HEX(SUBSTR(longblob_column, 3))
MEDIUMBLOBYbytesFROM_HEX(SUBSTR(mediumblob_column, 3))
TINYBLOBYbytesFROM_HEX(SUBSTR(tinyblob_column, 3))
DATEYdatePARSE_DATE('%Y-%m-%d', date_column)
DATETIMEYdatetimePARSE_DATETIME('%Y-%m-%dT%H:%M:%SZ', datetime_column)
TIMEYtimePARSE_TIME('%H:%M:%S', time_column)
TIMESTAMPYtimestampPARSE_TIMESTAMP('%Y-%m-%dT%H:%M:%SZ', timestamp_column)
YEARYintNone
DOUBLEYfloatNone
FLOATYfloatNone
VARCHAR(N)YstringNone
VARBINARY(N)YbytesFROM_HEX(SUBSTR(varbinary_column, 3))
CHAR(N)YstringNone
TEXTYstringNone
LONGTEXTYstringNone
MEDIUMTEXTYstringNone
TINYTEXTYstringNone
JSONYobjectJSON_PARSE(json_column)
ENUMYstringNone
SETYstringNone
BOOLYboolCAST(bool_column as bool)
GEOMETRYNNANA
POINTNNANA
LINESTRINGNNANA
POLYGONNNANA
MULTILINESTRINGNNANA
MULTIPOLYGONNNANA
GEOMETRYCOLLECTIONNNANA

#Unsupported Operations

Table level operations such as drop table, truncate table, and alter table are currently unsupported.

Join us on Slack!
Building on Rockset? Come chat with us!