Migrating the Entire MyCat Database to DDM
Scenario
The following describes how to migrate an entire MyCat database to DDM.
- Services may be interrupted during migration. The interruption duration depends on the amount of data to be migrated and network conditions.
- Data migration is complicated and is recommended during off-peak hours. This guide is for reference only. Design an appropriate migration scheme based on your service scenarios, data volume, and downtime requirements.
- If a large amount of data is involved, contact DDM technical engineers by submitting a service ticket or through after-sales services. Fully rehearse the migration before migrating data.
- You can access DDM only through an ECS. Therefore, you must export databases as files to the ECS, and then import data in the files into DDM from the ECS.
Preparations for Migration
- Prepare an ECS that can access MyCat, the target DDM instance, and the RDS DB instance associated with the target DDM instance.
- Ensure that MyCat, the target DDM instance, and the RDS DB instance associated with the target DDM instance are in the same VPC for network connectivity.
- Configure the same security group for the ECS running MyCat, the target DDM instance, and the RDS DB instance associated with the target DDM instance. If they belong to different security groups, configure their security group rules to allow them to access each other.
- Install an official MySQL client on the ECS. Version 5.6 or 5.7 is recommended.
- Install a Linux OS of the Red Hat series: yum install mysql mysql-devel
- Install a Linux OS of the Debian series: apt install mysql-client-5.7 mysql-client-core-5.7
- Ensure that sufficient disk space and memory are available on the ECS for storing and comparing dump files.
- Prepare a DDM instance that has been associated with an RDS DB instance, and configure the DDM account, schema, and logical table for it.
- MyCat 1.6 is used as an example.
Migration Scheme
Table types in MyCat and DDM are different from each other and migration schemes vary by table type, as described in Table 1.
| MyCat Table Type | DDM Table Type | Migration Scheme |
|---|---|---|
| Unsharded table | Unsharded table |
|
| Sharded table: hash sharding (including by date) | Sharded table: hash sharding (including date functions) |
|
| Sharded table: ranging sharding (including by date) | Sharded table: range sharding (including date functions) | |
| Global table | Global table |
Constraints
- To ensure data integrity, stop MyCat services before data migration.
- In this scenario, associating MyCat with DDM for data association is not supported. You must export data from MyCat and then import the data into DDM.
- The version of the RDS DB instance associated with the target DDM instance must be consistent with the version of MyCat.
Exporting Table Structure Data from MyCat
- Log in to the target ECS.
- Run the following command to export table structure data in the MyCat database. Set the parameters in italics to actual values. For details about the parameters, see Table 2.
mysqldump -h {DB_ADDRESS} -P {DB_PORT} -u {DB_USER} -p --skip-lock-tables --add-locks=false --set-gtid-purged=OFF --no-data --order-by-primary {DB_NAME} > {mysql_schema.sql} Enter password: **********Table 2 Parameter description Parameter
Description
Remarks
DB_ADDRESS
Connection address of a database whose data is to be exported
Mandatory
DB_PORT
Listening port of a database
Mandatory
DB_USER
Database user
Mandatory
DB_NAME
Database name
Mandatory
mysql_schema.sql
Generated name of a table structure file
The file varies depending on the table whose structure is exported.
You are advised to name the file in the format of "schema name" + "_" + "schema" to prevent data from being overwritten, for example, mysql_schema.sql.
mysql_data.sql
Generated name of a DB data file
N/A
Exporting Data from the Entire MyCat Database
- Log in to the ECS.
- Run the following command to export data of the MyCat database. Set the parameters in italics to actual values. For details about the parameters, see Table 2.
mysqldump -h {DB_ADDRESS} -P {DB_PORT} -u {DB_USER} -p --hex-blob --complete-insert --skip-lock-tables --add-locks=false --set-gtid-purged=OFF --quick --no-create-info --order-by-primary {DB_NAME} > {mysql_data.sql} Enter password: ********** - Run the following command on the ECS to view the exported SQL file.
ls -l
Importing Data in Unsharded Tables into the Target DDM Instance
On the ECS, use a MySQL client to connect to the RDS DB instance associated with the target DDM instance. Run the following commands to import data of the table structure text files and database files.
mysql -f -h {RDS_ADDRESS} -P {RDS_PORT} -u {RDS_USER} -p {DB_NAME} < {mysql_table_schema.sql}
Enter password: **********
mysql -f -h {RDS_ADDRESS} -P {RDS_PORT} -u {RDS_USER} -p {DB_NAME} < {mysq_table_data.sql}
Enter password: ********** - RDS_ADDRESS indicates the address of an RDS DB instance into which data is to be imported.
- RDS_PORT indicates the port number of an RDS DB instance.
- RDS_USER indicates the username of an RDS DB instance.
- DB_NAME indicates the name of an RDS database. If data of unsharded tables is to be imported, DB_NAME indicates the name of the first shard of RDS.
- mysql_table_schema.sql indicates the name of a table structure file to be imported.
- mysq_table_data.sql indicates the name of a table data file to be imported.
Importing Data (in a Sharded or Global Table) into the Target DDM Instance
mysql -f -h {DDM_ADDRESS} -P {DDM_PORT} -u {DDM_USER} -p {DB_NAME} < {mysql_schema.sql}
Enter password: ********** | Parameter | Description | Remarks |
|---|---|---|
| DDM_ADDRESS | Connection address of the DDM instance into which data is to be imported | View the connection address and port number on the Basic Information tab on the DDM console. |
| DDM_PORT | Listening port of the DDM instance into which data is to be imported | |
| DDM_USER | User accessing the DDM instance | Account for creating a schema. The account must have both read and write permissions. |
| DB_NAME | Name of the schema into which data is to be imported | N/A |
| mysql_data.sql | Name of the entire DB data file to be imported | Name of the file exported in 2 |
Last Article: Selecting a Distributed Transaction Mode
Next Article: Accessing DDM Through the JDBC Connection Pool
Did this article solve your problem?
Thank you for your score!Your feedback would help us improve the website.