Maxwell reads and converts MySQL binlogs into the JavaScript Object Notation (JSON) format. It is used to capture all data change events in a database. This topic describes how to use Maxwell to export data of a MySQL-compatible tenant of OceanBase Cloud in the JSON format.
Prerequisites
Before you use Maxwell, make sure that the following conditions are met:
- You have activated the Binlog service for OceanBase Cloud in the MySQL compatible mode. For more information, see Procedure.
- You have installed Java 1.8 or later.
- You have downloaded Maxwell. For more information, see the description of Maxwell at GitHub.
Procedure
Activate the Binlog service in OceanBase Cloud. In the left-side navigation pane of the OceanBase Cloud console, choose Instances > Tenant Management and activate the Binlog service. For more information, see Activate the Binlog service.
Configure Maxwell. Edit the
config.propertiesfile in the working directory of Maxwell. If this file does not exist, copyconfig.properties.example, rename it intoconfig.properties, and edit the file.user=maxwell password=yourpassword host=IP address of the server of the source MySQL-compatible tenant of OceanBase Cloud producer=stdoutstdoutindicates the standard output mode. With this configuration, Maxwell directly exports data to the console. To enable Maxwell to export data to other targets such as Kafka, change the value ofproducerand related configurations.Start Maxwell.
Run the following command to start Maxwell:
bin/maxwell --config config.propertiesView data changes Change data in OceanBase Cloud, for example, insert, update, or delete data. Then, observe the JSON data exported by Maxwell. Set the output mode of Maxwell to
stdoutin the command in Step 3. The possible return results are as follows:{ "database": "mydb", "table": "mytable", "type": "insert", "ts": 1589372847, "xid": 12345678, "commit": true, "data": { "id": 1, "column1": "value1", "column2": "value2" } }The return results show that data was inserted into the
mydb.mytabletable.
Notice
OceanBase Cloud V4.1.0 and later support Latin character sets. If you use OceanBase Cloud of a version earlier than V4.1.0 as the MetaDB for Maxwell, you must manually build the metadata tables of Maxwell.
In the following example, the latin1 character set is deleted from the CREATE TABLE statement of Maxwell.
CREATE TABLE IF NOT EXISTS `databases` (
id bigint auto_increment NOT NULL primary key,
schema_id bigint,
name varchar(255) charset 'utf8',
charset varchar(255),
index (schema_id)
);
This example describes how to operate a single metadata table. You need to perform the same operations on other metadata tables.