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 tenant of OceanBase Database in the JSON format.
Prerequisites
Before you use Maxwell, make sure that:
- You have installed OBLogProxy.
- You have installed Java 1.8 or later.
- You have downloaded Maxwell. For more information, see the description of Maxwell at GitHub.
Procedure
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=Server IP address of the source MySQL tenant in OceanBase Database 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.
- Perform data changes operations, for example, insert, update, or delete data in OceanBase Database.
- Observe the JSON data exported by Maxwell.
- Set the output mode of Maxwell to
stdout.
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 Database supports Latin character sets since V4.1.0. If you use OceanBase Database 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 only describes how to operate a single metadata table. You need to perform the same operations on other metadata tables.