为Debezium配置MySQL单机版
Debezium是一个开源的CDC (Change Data Capture)工具,用来实时监控数据库中的变化,生成事件流、存入Kafka。
Debezium支持多种主流数据库,MySQL是其中一种。使用该工具时,我们需要在MySQL端进行哪些设置呢?官方文档中对此语焉不详。好在文档中的Tutorial给我们提供了一些线索。Tutorial中所使用的MySQL单机版Docker Image,其构建文件在这儿:https://github.com/debezium/container-images/tree/main/examples/mysql/2.0。一共有三个文件:Dockerfile、inventory.sql、及mysql.cnf。
分析Dockerfile可知,inventory.sql是用来生成Tutorial所用的表、和数据,而mysql.cnf即为Debezium所需的特殊配置。
然而,从Dockerfile还可看出,该镜像的基础镜像是MySQL的官方镜像。而MySQL官方镜像中的参数配置可在这儿查到:https://github.com/docker-library/mysql/tree/master/8.0/config。
剔除两边重复的部分、及Debezium中过时的参数,可精简Debezium Tutorial中的mysql.cnf如下:
[mysqld]
user=mysql
# ----------------------------------------------
# Enable the binlog for replication & CDC
# ----------------------------------------------
# Enable binary replication log and set the prefix, expiration, and log format.
# The prefix is arbitrary, expiration can be short for integration tests but would
# be longer on a production system. Row-level info is required for ingest to work.
# Server ID is required, but this will vary on production systems
server-id = 223344
log_bin = mysql-bin
expire_logs_days = 1
binlog_format = row
# For Debezium MySQL connector
default_authentication_plugin = mysql_native_password
在这当中,user=mysql只是设置MySQL以非root用户运行,与Debezium无关。因此,有关的只有两部分,一部分是设置MySQL binlog,这是Debezium捕捉数据的地方;另一部分为设置default authentication plugin,其缺省值是caching_sha2_password,为了Debezium MySQL connector,需改为mysql_native_password。
按上述修改重新构建Docker Image,并将Debezium Tutorial中的quay.io/debezium/example-mysql替换为biandayu/example-mysql,Debezium工作正常。

相关推荐
-
MySQL 安装失败,提示Apply Security Settings 的处理办法
MySQL 安装失败,提示Apply Security Settings 的处理办法2025-04-20 01:54:57 -
MySQL事务隔离级别详解2025-04-20 01:44:01
-
一文说清nginx规则匹配(含案例分析)2025-04-20 01:10:02
-
运维服务篇:Nginx常用功能(rewrite重定向/location定位等)
运维服务篇:Nginx常用功能(rewrite重定向/location定位等)2025-04-20 00:55:25 -
php定义变量规则不能包含哪些字符?2025-04-20 00:27:24