ticdc创建同步任务时,下游tidb的root密码设置复杂,报错:[CDC:ErrSinkURIInvalid]sink uri invalid: parse "mysql://root:9CMv3k%a$6wyD=5*86@10.3.xx.99:4000/": invalid URL escape "%a$"

【 TiDB 使用环境】预生产环境到测试环境之间做cdc任务同步
【 TiDB 版本】v5.4.0
【复现路径】# tiup cdc cli changefeed create --pd=“http://10.3.xx.88:2379” --sink-uri=“mysql://root:9CMv3k%a$6wyD=586@10.3.xx.99:4000/" --changefeed-id=“bj_pre_to_test_01” --sort-engine=“unified” --config=“./bj_pre_to_test_01.toml” --start-ts=‘439311187320766467’
【遇到的问题:问题现象及影响】
报错如下:
Error: [CDC:ErrSinkURIInvalid]sink uri invalid: parse "mysql://root:9CMv3k%a$6wyD=5
81@10.3.xx.99:4000/”: invalid URL escape “%a$”
Usage:
cdc cli changefeed create [flags]

Flags:
-c, --changefeed-id string Replication task (changefeed) ID
–config string Path of the configuration file
–cyclic-filter-replica-ids uints (Experimental) Cyclic replication filter replica ID of changefeed (default [])
–cyclic-replica-id uint (Experimental) Cyclic replication replica ID of changefeed
–cyclic-sync-ddl (Experimental) Cyclic replication sync DDL of changefeed (default true)
–disable-gc-check Disable GC safe point check
-h, --help help for create
–no-confirm Don’t ask user whether to ignore ineligible table
–opts key=value Extra options, in the key=value format
–sink-uri string sink uri
–sort-engine string sort engine used for data sort (default “unified”)
–start-ts uint Start ts of changefeed
–sync-interval duration (Experimental) Set the interval for syncpoint in replication(default 10min) (default 10m0s)
–sync-point (Experimental) Set and Record syncpoint in replication(default off)
–target-ts uint Target ts of changefeed
–tz string timezone used when checking sink uri (changefeed timezone is determined by cdc server) (default “SYSTEM”)

Global Flags:
–ca string CA certificate path for TLS connection
–cert string Certificate path for TLS connection
-i, --interact Run cdc cli with readline
–key string Private key path for TLS connection
–log-level string log level (etc: debug|info|warn|error) (default “warn”)
–pd string PD address, use ‘,’ to separate multiple PDs (default “http://127.0.0.1:2379”)

[CDC:ErrSinkURIInvalid]sink uri invalid: parse “mysql://root:9CMv3k%a$6wyD=5*86@10.3.xx.99:4000/”: invalid URL escape “%a$”
【资源配置】
【附件:截图/日志/监控】

:thinking: 试试用 \ 对 % 转义下呢

对%转义,重新创建,报错如下:
[CDC:ErrSinkURIInvalid]sink uri invalid: parse “mysql://root:9CMv3k\%awyD=5*81@10.3.xx.99:4000/”: net/url: invalid userinfo

对$转义,重新创建,报错如下:
[CDC:ErrSinkURIInvalid]sink uri invalid: parse “mysql://root:9CMv3k%a$6wyD=5*81@10.3.xx.99:4000/”: invalid URL escape “%a$”

对$和%同时转义,重新创建,报错如下:
[CDC:ErrSinkURIInvalid]sink uri invalid: parse “mysql://root:9CMv3k\%a$6wyD=5*81@10.3.xx.99:4000/”: net/url: invalid userinfo

当 Sink URI 中包含特殊字符时,如 ! * ' ( ) ; : @ & = + $ , / ? % # [ ] ,需要对 URI 特殊字符进行转义处理。你可以使用 URI Encoder 工具对 URI 进行转义。

比如$做uri encode后变成%24

1 个赞

把整个sink-uri转码后,还是不行,我先创建一个新账号密码不复杂的做同步再说。

不用转整个sink-uri,只转特殊字符就行

– 只转义特殊字符:
%$=* – %25%24%3D*

转换后的%号,变成了%25,直接写到密码的位置,替换原来的%号?这样一来,%不还是特殊字符么?号,貌似没有转义成功,转义后,还是号。创建依然,失败:
报错如下:
[CDC:ErrInvalidChangefeedID]bad changefeed id, please match the pattern “[1]+(-[a-zA-Z0-9]+)*$, the length should no more than 128”, eg, “simple-changefeed-task”


  1. a-zA-Z0-9 ↩︎

只转义特殊字符,然后,拿转义后新字符替换原来的特殊字符。把changefeed_id命名中的下划线改为减号,再执行任务添加操作成功。非常感谢!

不过, 我尝试使用如下方法,没能成功:
若需要对 Sink URI 中的数据库密码使用 Base64 进行编码,可以参考如下命令:

echo -n '123456' | base64   # 假设待编码的密码为 123456

编码后的密码如下:

MTIzNDU2

密码换成这样试试:9CMv3k%25a%246wyD%3D581

新的报错是id格式不对,和sink-uri没关系。

%25能自动识别为encode格式,不用再次对%转义。