pgloader icon indicating copy to clipboard operation
pgloader copied to clipboard

Failed to connect to pgsql while the password contains char '@'

Open mgzhenhong opened this issue 9 months ago • 6 comments

full password is Hi@3812

use

load database from mysql://root:Hi@3812@localhost/enhscada_dc into postgresql://postgres:Hi@3812@localhost/enhscada_dc

or

load database from mysql://root:Hi%403812@localhost/enhscada_dc into postgresql://postgres:Hi%403812@localhost/enhscada_dc

are all auth failed, when cannot change the password, how can i fix it?

mgzhenhong avatar Mar 21 '25 12:03 mgzhenhong

Came looking for the same answer, thought mine was broken because my password contained [].

The answer to my problem was in https://github.com/dimitri/pgloader/issues/1197

--> instead of passing the password as part of the connection string, set $PGPASSWORD.

You have the @ twice, so that doesn't help with MySQL, but MYSQL_PWD should do the trick.

bbuechler avatar Mar 21 '25 22:03 bbuechler

Came looking for the same answer, thought mine was broken because my password contained [].

The answer to my problem was in #1197

--> instead of passing the password as part of the connection string, set $PGPASSWORD.

You have the @ twice, so that doesn't help with MySQL, but MYSQL_PWD should do the trick.

got it, thanks

mgzhenhong avatar Mar 22 '25 03:03 mgzhenhong

I faced the same problem and tried several approaches but got nothing working. Finally, I decided to run a simple command in terminal and that got it working.

What I tried that didn't work

  • Export global variable export PG_PASSWORD="MeandHi:m" and used $PG_PASSWORD in the connection string (failed)
  • Wrapp the passwords for both mssql and postgres in double-quotes (failed), then I used single-quotes (still failed)
  • Use the backslash character to escape colon in both connection strings (failed).
  • Use character encoding (URL-encoding) thereby using %3A in place of : (failed again).

What I tried that worked pgloader mssql://<username>:<password>@localhost/<database> pgsql://<username>:<password>@localhost/<database>

CharaD7 avatar Apr 29 '25 10:04 CharaD7

@CharaD7 , maybe:

  1. create a sanitizer:
cat > sanitize.sed << _EOF
#!/usr/bin/env sed
s/:/::/g
s/@/@@/g
_EOF
chmod +x sanitize.sed

  1. construct your conn. url from parts:
username_sanitized="$( echo "${username}" | sed -f ./sanitize.sed )"
password_sanitized="$( echo "${password}" | sed -f ./sanitize.sed )"
and then construct the conn. string:
conn_pgsql="postgresql://${username_sanitized}:${password_sanitized}@${server}/${db-schema}"

WDYT?

mvk avatar Apr 29 '25 10:04 mvk

@mvk Looks good but seems like too much work. I will consider doing this when running from a script. Thank you!

CharaD7 avatar Apr 29 '25 11:04 CharaD7

@ is a keyword you can try double @@ ,like this from mysql://root:Hi@@3812@localhost/enhscada_dc

sanfengchow avatar Sep 14 '25 10:09 sanfengchow