Data subscription Database table to the local

Last updated: 2020-02-19 19:31:07

PDF

This article will use a simple case to illustrate the function of pulling the corresponding table to the local file in the data subscription, and provide a simple LocalDemo download . The following operations will be done in the CentOS operating system.

Configure the environment

  • Java environment configuration
 yum install java-1.8.0-openjdk-devel 

Get the key

Login Access Management console Get the key.

Select data subscription

  1. Login DTS console Select "data subscription" on the left to enter the data subscription page.
  2. Select the name of the TencentDB instance to be synchronized, then click Launch, return to the data subscription, and click the data subscription you created. For a detailed introduction, please refer to How to get a data subscription .
  3. Check the corresponding DTS channel, IP and port, and then combine the previous key Enter into the corresponding LocalDemo.java.
 // Get the key from Cloud API and enter here
        context.setSecretId("AKIDfdsfdsfsdt1331431sdfds"); Please enter the secretID you got from Cloud API
        context.setSecretKey("test111usdfsdfsddsfRkeT"); Please enter the secretKey you got from Cloud API
    // Get the corresponding IP and port through data retrieval in the data migration service,and enter here 
        context.setServiceIp("10.66.112.181"); Please enter the IP you got from Data Subscription Configuration
        context.setServicePort(7507);
        Please enter the PORT you got from Data Subscription Configuration
        final DefaultSubscribeClient client = new DefaultSubscribeClient(context);
    // Enter the name of the database and table to be synchronized, and modify the name of the file to be stored.
        final String targetDatabase = "test"; Please enter the database name you want to subscribe
        final String targetTable = "alantest"; Please enter the table name you want to subscribe.

        final String fileName = "test.alan.txt"; Please enter the file name you want to put into the local

          client.addClusterListener(listener);
    // Get the configuration information of dts-channel through the configuration options of the data migration subscription, and enter here
    client.askForGUID("dts-channel-e4FQxtYV3It4test"); Please enter the name of the dts-channel you got from the data subscription
        client.start();

Compilation operation and verification

  1. [root@VM_71_10_centos ~]# javac -classpath binlogsdk-2.6.0-release.jar -encoding UTF-8 LocalDemo.java
  2. Then execute Launch, if there is no abnormal error, it is normal in the service, and then check the landing file set before.

java -XX:-UseGCOverheadLimit -Xms2g -Xmx2g -classpath .:binlogsdk-2.6.0-release.jar LocalDemo
  1. If you look at the test.alan.txt we set before, you can see that some data has been pulled locally.
[root@VM_71_10_centos ~]# cat test.alan.txt  
checkpoint:144251@3@357589@317713
record_id:000001000000000004D9110000000000000001
record_encoding:utf8
fields_enc:latin1,utf8
gtid:4f21864b-3bed-11e8-a44c-5cb901896188:1562
source_category:full_recorded
source_type:mysql
table_name:alantest
record_type:INSERT
db:test
timestamp:1523356039
primary:
Field name: id
Field type: 3
Field length: 2
Field value: 26
Field name: name
Field type: 253
Field length: 4
Field value: alan