When creating a sync task with TiCDC, an error occurs due to the complex root password of the downstream TiDB: [CDC:ErrSinkURIInvalid] sink uri invalid: parse "mysql://root:9CMv3k%a$6wyD=5*86@10.3.xx.99:4000/": invalid URL escape "%a$"

Note:
This topic has been translated from a Chinese forum by GPT and might contain errors.

Original topic: 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$”

| username: vcdog

[TiDB Usage Environment] Synchronize CDC tasks from pre-production environment to test environment
[TiDB Version] v5.4.0
[Reproduction Path] # 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’
[Encountered Problem: Problem Phenomenon and Impact]
Error reported as follows:
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$”
[Resource Configuration]
[Attachments: Screenshots/Logs/Monitoring]

| username: WalterWj | Original post link

:thinking: How about trying to escape % with ?

| username: vcdog | Original post link

For % escaping, recreate, the error is as follows:
[CDC:ErrSinkURIInvalid]sink uri invalid: parse “mysql://root:9CMv3k\%awyD=5*81@10.3.xx.99:4000/”: net/url: invalid userinfo

For $ escaping, recreate, the error is as follows:
[CDC:ErrSinkURIInvalid]sink uri invalid: parse “mysql://root:9CMv3k%a$6wyD=5*81@10.3.xx.99:4000/”: invalid URL escape “%a$”

For $ and % escaping simultaneously, recreate, the error is as follows:
[CDC:ErrSinkURIInvalid]sink uri invalid: parse “mysql://root:9CMv3k\%a$6wyD=5*81@10.3.xx.99:4000/”: net/url: invalid userinfo

| username: hey-hoho | Original post link

When the Sink URI contains special characters, such as ! * ' ( ) ; : @ & = + $ , / ? % # [ ], you need to escape the special characters in the URI. You can use the URI Encoder tool to escape the URI.

| username: hey-hoho | Original post link

For example, $ becomes %24 after URI encoding.

| username: vcdog | Original post link

After encoding, it becomes %24.

Even after encoding the entire sink-uri, it still doesn’t work. I’ll create a new account with a simpler password for synchronization first.

| username: hey-hoho | Original post link

There is no need to convert the entire sink-uri, just convert the special characters.

| username: vcdog | Original post link

– Only escape special characters:
%$=* – %25%24%3D*

The converted % sign becomes %25 and is directly written into the password position, replacing the original % sign? In this way, % is still a special character, right? The * sign seems to have not been successfully escaped; after escaping, it is still a * sign. Creation still fails:
Error message:
[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 ↩︎

| username: vcdog | Original post link

Escape only special characters, then replace the original special characters with the new escaped characters. Change the underscore in the changefeed_id name to a hyphen, and then the task addition operation is successful. Thank you very much!

However, I tried the following method but was unsuccessful:
If you need to encode the database password in the Sink URI using Base64, you can refer to the following command:

echo -n '123456' | base64   # Assuming the password to be encoded is 123456

The encoded password is as follows:

MTIzNDU2
| username: weixiaobing | Original post link

Try changing the password to this: 9CMv3k%25a%246wyD%3D581

| username: hey-hoho | Original post link

The new error is that the ID format is incorrect and has nothing to do with the sink-uri.

%25 can be automatically recognized as encoded format, no need to escape % again.