Step-by-Step Guide to Setting Up Canal for Real-Time MySQL Data Synchronization with Docker and Java
This tutorial explains how to configure Dockerized MySQL, set up Alibaba Canal as a binlog listener, adjust MySQL and Canal settings, and implement Java clients (including Spring Boot) to achieve real-time data synchronization, while also covering common errors and troubleshooting steps.
This article introduces how to use Alibaba Canal to capture MySQL binlog changes and synchronize them in real time.
It first explains the principle of Canal acting as a MySQL slave, then guides the setup of a MySQL instance inside Docker, including common Docker commands ( docker images, docker pull mysql,
docker run --name mysql-canal -e MYSQL_ROOT_PASSWORD=123456 -p 3306:3306 -d mysql --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci, docker exec -it <container_id> /bin/bash).
The guide details the required MySQL configuration for binlog (server-id, log_bin, character-set-server, default-storage-engine, etc.) and shows how to create a Canal user for replication.
It then presents the configuration files canal.properties (exposing ports and sync settings) and instance.properties (defining MySQL connection and tables to sync), followed by sample Java code using the raw Canal API and a Spring Boot integration, with notes on type‑conversion pitfalls when mapping database fields to Java objects.
Finally, the article lists common errors such as the caching_sha2_password Auth failed issue on MySQL 8.0 and provides the necessary adjustments to resolve them.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
TAL Education Technology
TAL Education is a technology-driven education company committed to the mission of 'making education better through love and technology'. The TAL technology team has always been dedicated to educational technology research and innovation. This is the external platform of the TAL technology team, sharing weekly curated technical articles and recruitment information.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
