Migrating Data from MySQL to MRS Hive
MRS provides enterprise-level big data clusters on the cloud. It contains HDFS, Hive, and Spark components and is used for massive data analysis of enterprises.
Hive supports SQL to help users perform extraction, transformation, and loading (ETL) operations on large-scale data sets. Querying large-scale data sets can take a long time. In many scenarios, you can create Hive partitions to reduce the total amount of data to be scanned each time. This significantly improves query performance.
Hive partitions are implemented by using HDFS subdirectories. Each subdirectory contains the column names and values of each partition. If there are multiple partitions, there are many HDFS subdirectories. It is not easy to load external data to each partition of the Hive table without relying on tools. With CDM, you can easily load data from external data sources (relational databases, object storage services, and file system services) to Hive partition tables.
This section describes how to migrate data from the MySQL database to the MRS Hive partition table.
Scenario
Suppose that there is a trip_data table in the MySQL database. The table stores cycling records such as the start time, end time, start sites, end sites, and rider IDs. For details about the fields in the trip_data table, see Figure 1.
The following describes how to use CDM to import the trip_data table in the MySQL database to the MRS Hive partition table. The procedure includes 5 steps:
Prerequisites
- You have bought the MRS clusters.
- You have sufficient EIP quota.
- You have obtained the IP address, port number, database name, username, and password for connecting to the MySQL database. In addition, the user must have the read and write permissions for the MySQL database.
Creating a Hive Partition Table on MRS Hive
1 | create table trip_data(TripID int,Duration int,StartDate timestamp,StartStation varchar(64),StartTerminal int,EndDate timestamp,EndStation varchar(64),EndTerminal int,Bike int,SubscriberType varchar(32),ZipCodev varchar(10))partitioned by (y int,ym int,ymd int);
|
The trip_data partition table has three partition fields: year, year and month, and year, month, and date of the start time of a ride. For example, if the start time of a ride is 2018/5/11 9:40, the record is saved in the trip_data/2018/201805/20180511 partition. When the records in the trip_data table are summarized, only part of the data needs to be scanned, greatly improving the performance.
Creating a CDM Cluster and Binding an EIP to the Cluster
- The DGC basic package includes a CDM cluster. If the cluster cannot meet your requirements, you can buy an incremental package to supplement the DGC basic instance. Create a CDM cluster. For details, see Buying a DGC Incremental Package. The key configurations are as follows:
- The flavor of the CDM cluster is selected based on the amount of data to be migrated. Generally, cdm.medium meets requirements for most migration scenarios.
- The CDM and MRS clusters must be in the same VPC, subnet, and security group.
- After the CDM cluster is created, on the Cluster Management page, click Bind EIP in the Operation column to bind an EIP to the cluster. The CDM cluster uses the EIP to access MySQL. Figure 2 Binding an EIP
If SSL encryption is configured for the access channel of a local data source, CDM cannot connect to the data source using the EIP.
Creating a MySQL Link
- On the Cluster Management page, click Job Management of the cluster and choose to enter the page for selecting the connector. See Figure 3.
- Select MySQL and click Next. On the page that is displayed, configure MySQL link parameters. Figure 4 Creating a MySQL link
Click Show Advanced Attributes to display optional parameters. For details, see Link to Relational Databases. Retain the default values for the optional parameters and configure the mandatory parameters described in Table 1.
Table 1 MySQL link parameters Parameter
Description
Example Value
Name
A unique link name
mysqllink
Database Server
IP address or domain name of the MySQL database
192.168.0.1
Port
MySQL database port
3306
Database Name
The name of the MySQL database
sqoop
Username
A user who has the read, write, and delete permissions on the MySQL database
admin
Password
The password of the user
N/A
Use Agent
Whether to extract data from the data source through an agent
Yes
Agent
Click Select and select the agent created in Connecting to an Agent.
N/A
- Click Save. The Link Management page is displayed.
If an error occurs when saving the settings, it is likely that the security settings of the MySQL database are incorrect. If this is the case, you may need to enable the EIP of the CDM cluster to access the MySQL database.
Creating a Hive Link
- Click Create Link and select MRS Hive to create an MRS Hive link.
- Click Next and configure the MRS Hive link parameters. See Figure 5.
Table 2 describes the parameters. Configure these parameters based on your actual situation.
Table 2 FusionInsight Hive link parameters Parameter
Description
Example Value
Name
Link name, which can be defined based on the data source type for easy memorization.
hivelink
Manager IP
IP address of MRS Manager. Click Select next to the Manager IP text box to select a created MRS cluster. CDM automatically fills in the authentication information.
127.0.0.1
Manager Port
FusionInsight/MRS Manager port
28443
CAS Server Port
CAS protocol port of FusionInsight/MRS Manager
20009
Verification Type
Authentication method used for accessing MRS- Simple: Select this if FusionInsight HD is in non-security mode.
- Kerberos: Select this if FusionInsight HD is in security mode.
SIMPLE
Hive Version
Hive version
HIVE_3_X
Username
When Authentication Method is set to Kerberos, set the username and password for logging in to MRS Manager.
cdm
Password
Password for logging in to MRS Manager
-
OBS Storage Support
The server must support OBS storage. When creating a Hive table, you can store the table in OBS.
No
Running Mode
This parameter is used only when the Hive version is HIVE_3_X. Possible values are:
- EMBEDDED: The link instance runs with CDM. This mode delivers better performance.
- STANDALONE: The link instance runs in an independent process. If CDM needs to connect to multiple Hadoop data sources (MRS, CloudTable, or Hadoop) with both Kerberos and Simple authentication modes, select STANDALONE or configure different agents.
Note: The STANDALONE mode is used to solve the version conflict problem. If the connector versions of the source and destination ends of the same data link are different, a JAR file conflict occurs. In this case, you need to place the source or destination end in the STANDALONE process to prevent the migration failure caused by the conflict.
- Agent: The link instance runs on an agent.
EMBEDDED
- Click Save. The Link Management page is displayed.
Creating a Migration Job
- Choose to create a data migration job. Figure 6 illustrates how to create a migration job.
Set Clear Data Before Import to Yes, so that the data in the Hive table will be cleared before data import.
- After the parameters are configured, click Next. The Map Field tab page is displayed. See Figure 7.
Map the fields of the MySQL table and Hive table. The Hive table has three more fields y, ym, and ymd than the MySQL table. These are the Hive partition fields. Because the fields of the source table cannot be directly mapped to the destination table, you need to configure an expression to extract data from the StartDate field in the source table.
- Click
to display the Converter List dialog box, and then choose . See Figure 8. The expressions for the y, ym, and ymd fields are as follows:
DateUtils.format(DateUtils.parseDate(row[2],"yyyy-MM-dd HH:mm:ss.SSS"),"yyyy")
DateUtils.format(DateUtils.parseDate(row[2],"yyyy-MM-dd HH:mm:ss.SSS"),"yyyyMM")
DateUtils.format(DateUtils.parseDate(row[2],"yyyy-MM-dd HH:mm:ss.SSS"),"yyyyMMdd")
The expressions in CDM support field conversion of common character strings, dates, and values. For details, see Field Conversion.
- Click Next and set task parameters. Generally, you can retain the default values for all parameters. In this step, you can configure the following optional functions:
- Retry Upon Failure: If the job fails, you can determine whether to automatically retry the job. Retain the default value Never.
- Group: Select which group the job belongs to. The default group is DEFAULT. On the Job Management page, jobs can be displayed, started, or exported by group.
- Schedule Execution: To configure scheduled jobs, see Scheduling Job Execution. Retain the default value No.
- Concurrent Extractors: Enter the number of extractors to be executed concurrently. Retain the default value 1. The maximum number of concurrent extractors in a single job is 500.
- Write Dirty Data: Specify this parameter if data that fails to be processed or filtered out during job execution needs to be written to OBS for future viewing. Before writing dirty data, create an OBS link. Retain the default value No so that dirty data is not recorded.
- Delete Job After Completion: Retain the default value Do not delete.
- Click Save and Run. The Job Management page is displayed, on which you can view the job execution progress and result.
- After the job is successfully executed, in the Operation column of the job, click Historical Record to view the job's historical execution records and read/write statistics.
On the Historical Record page, click Log to view the job logs.
Last Article: Migrating Data Oracle to CSS
Next Article: Migrating Data from OSS to OBS






Did this article solve your problem?
Thank you for your score!Your feedback would help us improve the website.