How to Sync MySQL to Elasticsearch with DBSyncer: A Step‑by‑Step Guide

This guide introduces the open‑source DBSyncer tool, explains its key features, shows how to install it via Docker, and provides detailed step‑by‑step examples of synchronizing MySQL tables to another MySQL instance and to Elasticsearch, including configuration, field mapping, and verification.

Su San Talks Tech
Su San Talks Tech
Su San Talks Tech
How to Sync MySQL to Elasticsearch with DBSyncer: A Step‑by‑Step Guide

Introduction

DBSyncer is an open‑source data‑synchronization tool that supports MySQL, Oracle, PostgreSQL, Elasticsearch, Kafka, file systems and other sources. It provides a visual web console, real‑time monitoring, and extensible plugins for custom sync logic.

Key Features

Combination‑driven sync: define custom source‑target pairs, e.g., MySQL to Elasticsearch.

Real‑time monitoring: supports full and incremental sync, with status, logs and system metrics.

Plugin development: write code to customize transformation and sync logic.

Installation via Docker

Use Docker to pull and run the DBSyncer image:

docker pull registry.cn-hangzhou.aliyuncs.com/xhtb/dbsyncer:latest

Start the container:

docker run -p 18686:18686 --name=db-syncer \
  -e TZ="Asia/Shanghai" \
  -v /mydata/db-syncer/data:/app/dbsyncer/data \
  -v /mydata/db-syncer/plugins:/app/dbsyncer/plugins \
  -d registry.cn-hangzhou.aliyuncs.com/xhtb/dbsyncer:latest

After the container is running, access the web console at http://192.168.3.101:18686 using the default credentials admin:admin.

Usage Example: MySQL to MySQL Sync

Sample Table

CREATE TABLE `product` (
  `id` bigint(20) NOT NULL AUTO_INCREMENT,
  `title` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `sub_title` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `price` decimal(10,2) NULL DEFAULT NULL,
  `pic` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  PRIMARY KEY (`id`) USING BTREE
) ENGINE=InnoDB AUTO_INCREMENT=2 CHARACTER SET=utf8 COLLATE=utf8_general_ci ROW_FORMAT=Dynamic;

Create two databases, mall_dev (source) and mall_test (target). The product table in mall_dev contains data, while mall_test is empty. The goal is to sync the source data to the target.

In the DBSyncer console, add connections for both databases, then create a driver that maps the source to the target, select all fields (or specific ones), and start the sync.

Usage Example: MySQL to Elasticsearch Sync

Create Elasticsearch Index

PUT /product_index
{
  "mappings": {
    "properties": {
      "id": {"type": "long"},
      "title": {"type": "text"},
      "sub_title": {"type": "text"},
      "pic": {"type": "text"},
      "price": {"type": "double"}
    }
  }
}

Execute the above request in Kibana Dev Tools (Kibana URL: http://192.168.3.101:5601) to create the product_index.

Add an Elasticsearch connection in DBSyncer (password can be arbitrary if not set), then create a driver that syncs from MySQL to the newly created index, configure field mappings (ensure the primary key is set), and start the driver.

After starting the driver, the data is transferred to Elasticsearch and can be queried via Kibana.

Conclusion

The article demonstrates how to use DBSyncer’s visual interface to perform full‑batch synchronization between MySQL and Elasticsearch, as well as MySQL‑to‑MySQL sync. DBSyncer also supports incremental sync and custom plugins for advanced scenarios.

Project Repository

https://gitee.com/ghi/dbsyncer

DockerElasticsearchMySQLopen-sourceData SynchronizationDBSyncer
Su San Talks Tech
Written by

Su San Talks Tech

Su San, former staff at several leading tech companies, is a top creator on Juejin and a premium creator on CSDN, and runs the free coding practice site www.susan.net.cn.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.