Migrate databases for cloud adoption
Database migration is a major cloud adoption challenge. When database domain names or IPs are hardcoded in application clients, migrating to ApsaraDB RDS requires modifying client code—a complex, high-risk process.
Solution
Use Private Zone to create a database domain name matching your original on-premises domain name, then add a CNAME record pointing it to the internal endpoint of your ApsaraDB RDS instance. This eliminates client code changes during migration, reducing refactoring effort and risk.
Before you begin
-
Prepare the following resources.
Resource
Quantity
Sample value
On-premises database domain name
1
db.example.com
ECS instance
1 or more
1.1.XX.XX, 2.2.XX.XX
ApsaraDB RDS instance
1
rm-2ze44q293vs56l9po*****.mysql.rds.aliyuncs.com
Procedure
1. Get the RDS internal endpoint
-
Log on to the ApsaraDB RDS Console. In the left-side navigation pane, click Instances. On the Instances page, click your target instance ID in the Instance ID/Name column.
-
In the left-side navigation pane, click Database Connection and copy the domain name next to Internal Endpoint.
2. Add a Private Zone and CNAME record
-
Navigate to the Alibaba Cloud DNS - Private Zone console.
-
On the Private Zone page, click the User Defined Zones tab.
-
Click Add Zone. In the Add Private Zone Domain (Zone) dialog box, enter your domain name, such as db.example.com. For the zone type, we recommend Private Zone Acceleration. Click OK.
-
On the User Defined Zones page, find the domain
db.example.comand click Settings in the Actions column. -
On the Settings page, click Add DNS Record. Set Record Type to CNAME, Hostname to @, and DNS Request Source to Default. For Record Value, enter the internal endpoint of your ApsaraDB RDS instance, such as
rm-2ze44q293vs56l9po*****.mysql.rds.aliyuncs.com. Use your actual endpoint. Click OK. -
Return to the User Defined Zones page. Find the domain
db.example.comand click Effective Scope in the Actions column. On the Zone Settings page, set the Effective Scope by associating the zone with your database VPC.
3. Verify the configuration
-
Log on to an ECS instance in the associated VPC and run the following command to test DNS resolution. A successful response is shown below. If resolution fails, verify your DNS record configuration.
dig db.example.com; <<>> DiG 9.11.4-P2-RedHat-9.11.4-16.P2.el7_8.6 <<>> db.example.com ;; global options: +cmd ;; Got answer: ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 44628 ;; flags: qr rd ra; QUERY: 1, ANSWER: 2, AUTHORITY: 0, ADDITIONAL: 1 ;; OPT PSEUDOSECTION: ; EDNS: version: 0, flags:; udp: 4096 ;; QUESTION SECTION: ;db.example.com. IN A ;; ANSWER SECTION: db.example.com. 60 IN CNAME rm-2ze44q293vs5619po125010.mysql.rds.aliyuncs.com. rm-2ze44q293vs5619po125010.mysql.rds.aliyuncs.com. 60 IN A 172.17.154.201 ;; Query time: 5 msec ;; SERVER: 100.100.2.136#53(100.100.2.136) ;; WHEN: Mon Jul 06 16:20:42 CST 2020 ;; MSG SIZE rcvd: 122 -
Log on to an ECS instance in the same VPC and run the following command to test the RDS connection. A successful connection produces the following output.
mysql -utest_dns -ptest_dns -hdb.example.com -P3306 -Dtest_dns[root@xxx ~]# mysql -utest_dns -ptest_dns -hdb.example.com -P3306 -Dtest_dns mysql: [Warning] Using a password on the command line interface can be insecure. Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 94 Server version: 8.0.18 Source distribution Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | test_dns | +--------------------+ 3 rows in set (0.00 sec) mysql>
Troubleshooting
-
ERROR 2003 (HY000): Can’t connect to MySQL server on ‘db.example.com’ (110): Connection failure. Add the ECS instance IP address to the database whitelist.
[root@xxx ~]# mysql -utest_dns -hdb.example.com -P3306 -Dtest_dns test_dns ERROR 2003 (HY000): Can’t connect to MySQL server on ‘db.example.com’ (110)