Using CDM to Migrate MySQL Data to the GaussDB(DWS) Cluster
This section describes how to use Cloud Data Migration (CDM) to migrate MySQL data to GaussDB(DWS) clusters in batches.
This section contains the following parts:
- Checking Data Before Migration
- Creating a GaussDB(DWS) Cluster
- Creating a CDM Cluster
- Creating a Link
- Creating and Migrating a Job
- Verifying Data Consistency After Migration
Scenario Description
CDM can migrate an entire cloud/on-premises MySQL database or a single table. The migration of an on-premises MySQL database is used as an example.
- On-premises MySQL data migration:
CDM accesses the MySQL database through the public IP address. CDM and GaussDB(DWS) are in the same VPC. CDM establishes JDBC connections respectively with MySQL and GaussDB(DWS).
- Cloud RDS MySQL data migration:
RDS, CDM, and GaussDB(DWS) are in the same VPC. CDM establishes JDBC connections respectively with MySQL and GaussDB(DWS). If cloud RDS and GaussDB(DWS) are not in the same VPC, CDM uses the EIP to access RDS.
Checking Data Before Migration
- Connect to the MySQL DB instance and check the MySQL database status.
mysql -h <host>-P <port>-u <userName>-p--ssl-ca=<caDIR>
Parameter
Description
<host>
Address for connecting to the MySQL database.
<port>
Database port. By default, the value is 3306.
<userName>
MySQL administrator account. The default value is root.
<caDIR>
Path of the CA certificate. The file must be stored in the path where the command is executed.
Enter the password of the database account as prompted:
Enter password:
- Analyze the name and code of the databases to be migrated, and the name and attributes of the tables to be migrated.
For example, the destination MySQL databases to be migrated are test01, test02, and the encoding format. The test01 library contains the orders, persons, and persons_b tables and the persons_beijing view. The test02 library contains the persons_c table.
- Query the database name.
1
show databases;
- Query the database code.
1 2
use <databasename>; status;
- Query the database table.
1 2
use <databasename>; show full tables;
- The GaussDB(DWS) database is case-insensitive. If the original MySQL database contains table names that contain both uppercase and lowercase letters or only uppercase letters, for example, Table01 and TABLE01, you need to change the table names to lowercase letters before the migration. Otherwise, GaussDB(DWS) cannot identify the tables after migration.
- You are advised to set the MySQL database to be case-insensitive by modifying lower_case_table_names to 1 in /etc/my.cnf and restarting the MySQL service.
- Check the attributes of each table for comparison after the migration.
1 2
use <databasename>; desc <table name>;
- Query the database name.
Creating a GaussDB(DWS) Cluster
- For details, see Creating a Cluster. You can select China-Hong Kong for Region.
Ensure that the GaussDB(DWS) cluster and CDM cluster are in the same region and VPC.
- For details, see Using the gsql Client to Connect to a Cluster.
- Create the target databases test01 and test02 in Checking Data Before Migration with the same name and database code as the original MySQL database.
1 2
create database test01 with encoding 'UTF-8' dbcompatibility 'mysql' template template0; create database test02 with encoding 'UTF-8' dbcompatibility 'mysql' template template0;
Creating a CDM Cluster
- Log in to the HUAWEI CLOUD management console.
- Choose Migration > Cloud Data Migration.
- Click Buy CDM Cluster and set the following parameters:
Table 1 Parameter description Parameter
Value
Region
CN-Hong Kong. Choose the region of your GaussDB(DWS).
AZ
AZ1 (If the desired resources are sold out in the current AZ, change the AZ and try again.)
Name
CDM-demo
Instance Type
cdm.large (Select other flavors if the flavor is sold out.)
VPC
demo-vpc (in the same VPC as GaussDB(DWS))
Subnet
subnet-f377(10.1.0.0/24) (example)
Security Group
-
Enterprise Project
Default
- Click Buy Now, confirm all the parameters and click Submit.
- Go back to the Cluster Management page. Cluster creation takes about 5 minutes. After the cluster is created, click Bind EIP in the Operation column of the cluster.
- Select an available EIP and click OK. If no EIP is available, switch to the EIP page to purchase an EIP.
Creating a Link
- When creating a MySQL connection for the first time, upload a driver.
- Access the MySQL driver and download the 5.1.48 version.
- Download the package to the local host and decompress it to obtain mysql-connector-java-xxx.jar.
- On the Cluster Management page, click Job Management in the Operation column of the cluster and choose Links > Driver Management.
- Click Upload on the right of MySQL, select mysql-connector-java-xxx.jar, and click Upload.
- Access the MySQL driver and download the 5.1.48 version.
- Create a MySQL connection.
- On the Cluster Management page, click Job Management in the Operation column of the cluster and choose Links > Create Link.
- Select MySQL and click Next. (If the RDS is deployed on the cloud, select RDS for MySQL.)
- Enter the connection information according to Table 2, and click Test. If the test is successful, click Save.
If the test fails, check whether CDM connects to the MySQL database using the public IP address. If the public IP address is used, bind the public IP address by referring to 5.
Table 2 MySQL link information Parameter
Value
Name
MySQL
Database Server
192.168.1.100 (This is an example, enter the actual public IP address of the on-premises MySQL database. Ensure that the whitelist access permission has been enabled on the MySQL server.)
Port
3306
Database Name
test01
User
root
Password
Password of the user root.
Use Local API
No
Use Agent
No
- Create a GaussDB(DWS) link.
- On the Cluster Management page, click Job Management in the Operation column of the cluster and choose Links > Create Link.
- Select Data Warehouse Service and click Next.
- Enter the connection information according to Table 3, and click Test. If the test is successful, click Save.
Table 3 GaussDB(DWS) connection information Parameter
Value
Column
DWS-test01
Database Server
Click Select and select the GaussDB(DWS) cluster to be connected from the cluster list.
NOTE:The system automatically displays the GaussDB(DWS) clusters in the same region and VPC. If no GaussDB(DWS) cluster is available, manually enter the IP address of the GaussDB(DWS) cluster that has been connected to the network.
Port
8000
Database Name
test01 (Ensure that the corresponding database has been manually created on GaussDB(DWS) by referring to 3.)
User
dbadmin
Password
Password of user dbadmin
Use Agent
No
- Repeat 3.a to 3.c to create the DWS-test02 link.
Creating and Migrating a Job
- On the Cluster Management page, click Job Management in the Operation column of the cluster and choose Entire DB Migration > Create Job.
- Set the following parameters and click Next.
- Job Name: MySQL-DWS-test01
- Source Job Configuration:
- Source Link Name: MySQL
- Destination Job Configuration:
- Destination Link Name: DWS-test01
- Automatic Table Creation: The table is created when it does not exist.
- isCompress: Yes
- Orientation: COLUMN
- Retain the default value for other settings.
- Select all tables, click , and click Next.
- Retain the default settings and click Save and Run.
- Check the job running status. If the status is Succeeded, the migration is successful.
- Repeat 1 to 5 to migrate all tables in the test02 database.
When creating a job, select test02 for the GaussDB(DWS) database of the target source.
Verifying Data Consistency After Migration
- Use gsql to connect to the test01 cluster of GaussDB(DWS).
gsql -d test01 -h IP address of the host -p 8000 -U dbadmin -W database user password -r;
- Query tables in the test01 database.
1
select * from pg_tables where schemaname= 'public';
- Check whether the data in each table is complete and whether the columns are complete.
1 2
select count(*) from table name; \d+ table name;
- Perform sampling check to verify table data.
1
select * from persons where city = 'Beijing' order by id_p;
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot