This topic describes how to use Canal and the OceanBase Binlog service to synchronize data from OceanBase Database to a MySQL database.
How OceanBase CDC works
OceanBase Binlog service is an incremental log proxy service for OceanBase Database. Built on libobcdc (formerly known as liboblog), it provides real-time access to and management of incremental links as a service, making it easy for applications to consume incremental logs from OceanBase Database. It meets the need to subscribe to incremental logs in network-isolated environments and offers multiple link access methods.
By parsing MySQL binlogs, Canal extracts incremental data from databases and sends it to subscribers for consumption and processing. This makes it easy to implement real-time data synchronization, real-time analytics, and other use cases.
For the official releases and usage documentation of Canal, see alibaba/canal.
The data link is as follows:
ob_cluster -> obbinlog -> canal_server -> canal_adapter -> mysql
The components are described as follows:
OceanBase Database: The business database that needs to generate Binlog logs.
OceanBase Database Proxy: The ODP (also known as OBProxy) for the business database, which provides connection services for clients subscribing to Binlog.
OceanBase Binlog Tool: The core component of OceanBase Binlog service,
obbinlog(formerly known asoblogproxy), which pulls clog and generates Binlog logs.Canal Server: The server-side component of Canal. It simulates the behavior of a MySQL slave to parse Binlog logs from the source and convert incremental data into CanalEntries for downstream consumption.
Canal Adapter: The client-side adapter of Canal. It parses CanalEntries and synchronizes incremental data to the destination. This topic uses its RDB module to synchronize data to a MySQL database.
Procedure
Step 1: Enable the OceanBase Binlog service
Follow the steps in Create a Binlog Cluster to install and deploy the OceanBase Binlog service.
On the tenant overview page in OCP, enable the Binlog service for the business tenant and associate it with the OBProxy cluster of that tenant. The Binlog service can be enabled only for tenants in MySQL-compatible mode. For more information, see Manage the binlog service for a tenant.
Create a user for data synchronization.
Execute the following SQL statement in the business tenant to create a user and grant read permissions.
CREATE USER 'canal'@'%' IDENTIFIED BY '******'; GRANT SELECT ON *.* TO 'canal'@'%';
Step 2: Install Canal Server
Download the software package.
Download canal.deployer-1.1.8.tar.gz.
wget https://github.com/alibaba/canal/releases/download/canal-1.1.8/canal.deployer-1.1.8.tar.gzDecompress the package to the
/Canal_Home/canaldirectory.mkdir /Canal_Home/canal && tar zxvf canal.deployer-1.1.8.tar.gz -C /Canal_Home/canalConfigure the canal instance.
Modify
/Canal_Home/canal/conf/example/instance.propertiesto configure the connection to the source OceanBase database. Set the connection address to the ODP address and port of the business tenant, and specify the username in the formatusername@tenant_name#cluster_name.cd /Canal_Home/canal/conf/example vi instance.properties # Source connection information, including the ODP address and port. canal.instance.master.address=10.10.10.1:2883 canal.instance.dbUsername=canal@mysql001#test4000 canal.instance.dbPassword=****** # Log filter. The format is database name.table name, and regular expressions are supported. canal.instance.filter.regex=.*\\..*Note
After the Binlog service is enabled, ODP forwards client Binlog subscription requests to the corresponding Binlog instance. You can therefore subscribe to incremental logs of OceanBase Database simply by connecting Canal to ODP.
Start Canal Server.
cd /Canal_Home/canal && sh bin/startup.shCheck the logs to confirm that Canal Server has started successfully.
tail -f logs/canal/canal.log
Step 3: Configure the RDB adapter
Download the software package.
Download canal.adapter-1.1.8.tar.gz.
wget https://github.com/alibaba/canal/releases/download/canal-1.1.8/canal.adapter-1.1.8.tar.gzDecompress the package to the
/Canal_Home/adapterdirectory.mkdir /Canal_Home/adapter && tar zxvf canal.adapter-1.1.8.tar.gz -C /Canal_Home/adapterModify the
application.ymlfile.Modify
/Canal_Home/adapter/conf/application.ymlto configure the RDB adapter to connect to Canal Server in TCP mode, and specify the connection settings for the target MySQL database.cd /Canal_Home/adapter/conf vi application.yml canal.conf: mode: tcp #tcp kafka rocketMQ rabbitMQ consumerProperties: # canal tcp consumer canal.tcp.server.host: 127.0.0.1:11111 canalAdapters: - instance: example # canal instance Name or mq topic name groups: - groupId: g1 outerAdapters: - name: logger - name: rdb key: mysql1 properties: jdbc.driverClassName: com.mysql.cj.jdbc.Driver jdbc.url: jdbc:mysql://10.10.10.1:3306/test_data?useUnicode=false jdbc.username: root jdbc.password: ******Modify the adapter database/table mapping. The following example modifies the database mapping.
cd /Canal_Home/adapter/conf/rdb vi mytest_user.yml ## Mirror schema synchronize config dataSourceKey: defaultDS destination: example groupId: g1 outerAdapterKey: mysql1 concurrent: true dbMapping: mirrorDb: true database: test_dataStart Canal Adapter.
cd /Canal_Home/adapter && sh bin/startup.shCheck data synchronization.
Write data to the source OceanBase database and verify that the data is synchronized to the destination MySQL database.
Limitations
Tables to be synchronized must have a primary key. Otherwise, deleting any record from a table without a primary key at the source causes the entire table to be deleted at the destination.
DDL operations support creating new tables and adding columns.