{"id":200953,"date":"2025-05-06T08:00:20","date_gmt":"2025-05-06T00:00:20","guid":{"rendered":"https:\/\/server.hk\/cnblog\/200953\/"},"modified":"2025-05-06T08:00:20","modified_gmt":"2025-05-06T00:00:20","slug":"flink-cdc-%e7%9b%91%e5%90%ac-mysql-%e4%ba%8c%e8%bf%9b%e5%88%b6%e4%b8%bb%e9%94%ae%e6%97%b6%e5%87%ba%e7%8e%b0-classcastexception-%e5%a6%82%e4%bd%95%e8%a7%a3%e5%86%b3%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/200953\/","title":{"rendered":"Flink CDC \u76d1\u542c MySQL \u4e8c\u8fdb\u5236\u4e3b\u952e\u65f6\u51fa\u73b0 ClassCastException \u5982\u4f55\u89e3\u51b3\uff1f"},"content":{"rendered":"<p><b><\/b> <\/p>\n<h1>Flink CDC \u76d1\u542c MySQL \u4e8c\u8fdb\u5236\u4e3b\u952e\u65f6\u51fa\u73b0 ClassCastException \u5982\u4f55\u89e3\u51b3\uff1f<\/h1>\n<p>\u54c8\u55bd\uff01\u5927\u5bb6\u597d\uff0c\u5f88\u9ad8\u5174\u53c8\u89c1\u9762\u4e86\uff0c\u6211\u662f\u4e3b\u673a\u5b9d\u8d1d\u7684\u4e00\u540d\u4f5c\u8005\uff0c\u4eca\u5929\u7531\u6211\u7ed9\u5927\u5bb6\u5e26\u6765\u4e00\u7bc7\uff0c\u672c\u6587\u4e3b\u8981\u4f1a\u8bb2\u5230\u7b49\u7b49\u77e5\u8bc6\u70b9\uff0c\u5e0c\u671b\u5927\u5bb6\u4e00\u8d77\u5b66\u4e60\u8fdb\u6b65\uff0c\u4e5f\u6b22\u8fce\u5927\u5bb6\u5173\u6ce8\u3001\u70b9\u8d5e\u3001\u6536\u85cf\u3001\u8f6c\u53d1! \u4e0b\u9762\u5c31\u4e00\u8d77\u6765\u770b\u770b\u5427\uff01<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241122\/173228727867409b2ebe79f.jpg\" class=\"aligncenter\"><\/p>\n<p><strong>flink cdc \u76d1\u542c mysql binary \u4e3b\u952e\u65f6\u51fa\u73b0 classcastexception<\/strong><\/p>\n<p>\u4f7f\u7528 flink cdc \u76d1\u542c mysql \u65f6\uff0c\u5982\u679c mysql \u8868\u7684\u4e3b\u952e\u662f\u4e8c\u8fdb\u5236\u683c\u5f0f\uff0c\u53ef\u80fd\u4f1a\u9047\u5230\u4ee5\u4e0b\u9519\u8bef\uff1a<\/p>\n<pre>caused by: java.lang.classcastexception: [b cannot be cast to java.lang.comparable<\/pre>\n<p><strong>\u95ee\u9898\u5206\u6790<\/strong><\/p>\n<p>\u6b64\u9519\u8bef\u8868\u660e\u5728\u62c6\u8868\u65f6\u51fa\u73b0\u4e86\u95ee\u9898\u3002flink cdc \u5c06\u8868\u62c6\u5206\u4e3a\u66f4\u5c0f\u7684\u5206\u7247\uff0c\u7528\u4e8e\u5e76\u884c\u8bfb\u53d6\u3002\u62c6\u5206\u65f6\uff0cflink \u4f1a\u6bd4\u8f83\u4e3b\u952e\u503c\u4ee5\u786e\u5b9a\u5206\u7247\u7684\u8fb9\u754c\u3002\u4f46\u662f\uff0c\u5bf9\u4e8e\u4e8c\u8fdb\u5236\u683c\u5f0f\u7684\u4e3b\u952e\uff0c\u4e3b\u952e\u503c\u65e0\u6cd5\u76f4\u63a5\u8f6c\u6362\u4e3a\u53ef\u6bd4\u8f83\u7684\u5bf9\u8c61\uff0c\u56e0\u6b64\u4f1a\u51fa\u73b0 classcastexception\u3002<\/p>\n<p><strong>\u89e3\u51b3\u65b9\u6848<\/strong><\/p>\n<p>\u89e3\u51b3\u6b64\u95ee\u9898\u7684\u65b9\u6cd5\u662f\u5347\u7ea7\u5230 flink cdc 2.1.2 \u6216\u66f4\u9ad8\u7248\u672c\u3002\u5728\u8fd9\u4e9b\u7248\u672c\u4e2d\uff0c\u5df2\u7ecf\u4fee\u590d\u4e86\u8be5\u95ee\u9898\u3002\u6b64\u5916\uff0c\u8fd8\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u65b9\u5f0f\u89e3\u51b3\u95ee\u9898\uff1a<\/p>\n<ul>\n<li>\u5c06 mysql \u8868\u7684\u4e3b\u952e\u66f4\u6539\u4e3a\u975e\u4e8c\u8fdb\u5236\u683c\u5f0f\u3002<\/li>\n<li>\u4f7f\u7528 flink \u63d0\u4f9b\u7684 binaryprefixboundednessassigner \u6765\u5904\u7406\u4e8c\u8fdb\u5236\u4e3b\u952e\u3002<\/li>\n<\/ul>\n<p><strong>\u5177\u4f53\u6b65\u9aa4<\/strong><\/p>\n<p>\u5c06 flink cdc 2.1.1 \u5347\u7ea7\u5230 2.1.2 \u6216\u66f4\u9ad8\u7248\u672c\uff1a<\/p>\n<pre>mvn dependency:upgrade -dartifact org.apache.flink:flink-connector-mysql-cdc<\/pre>\n<p>\u4f7f\u7528 binaryprefixboundednessassigner \u6765\u5904\u7406\u4e8c\u8fdb\u5236\u4e3b\u952e\uff1a<\/p>\n<pre>ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();\n\/\/ \u521b\u5efa MySQL source\nCDCSource&lt;Tuple5&lt;ByteString, ByteString, BigInteger, ByteString, Long&gt;&gt; source = CDCSource.&lt;Tuple5&lt;ByteString, ByteString, BigInteger, ByteString, Long&gt;&gt;builder()\n        .hostname(\"localhost\")\n        .port(3306)\n        .database(\"test_db\")\n        .tableList(\"test_table\")\n        .username(\"root\")\n        .password(\"root\")\n        \/\/ \u4f7f\u7528 BinaryPrefixBoundednessAssigner \u5904\u7406\u4e8c\u8fdb\u5236\u4e3b\u952e\n        .assigners(new BinaryPrefixBoundednessAssigner())\n        .build();<\/pre>\n<p>\u5230\u8fd9\u91cc\uff0c\u6211\u4eec\u4e5f\u5c31\u8bb2\u5b8c\u4e86\u300aFlink CDC \u76d1\u542c MySQL \u4e8c\u8fdb\u5236\u4e3b\u952e\u65f6\u51fa\u73b0 ClassCastException \u5982\u4f55\u89e3\u51b3\uff1f\u300b\u7684\u5185\u5bb9\u4e86\u3002\u4e2a\u4eba\u8ba4\u4e3a\uff0c\u57fa\u7840\u77e5\u8bc6\u7684\u5b66\u4e60\u548c\u5de9\u56fa\uff0c\u662f\u4e3a\u4e86\u66f4\u597d\u7684\u5c06\u5176\u8fd0\u7528\u5230\u9879\u76ee\u4e2d\uff0c\u6b22\u8fce\u5173\u6ce8\u4e3b\u673a\u5b9d\u8d1d\u516c\u4f17\u53f7\uff0c\u5e26\u4f60\u4e86\u89e3\u66f4\u591a\u5173\u4e8e\u7684\u77e5\u8bc6\u70b9\uff01<\/p>\n<dl>\n<dt>\n <\/dt>\n<\/dl>\n","protected":false},"excerpt":{"rendered":"<p>Flink CDC \u76d1\u542c MyS&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[101],"tags":[],"class_list":["post-200953","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/200953","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=200953"}],"version-history":[{"count":0,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/200953\/revisions"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=200953"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=200953"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=200953"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}