Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
mgzhenhong opened this issue Mar 21, 2025 · 5 comments
Open

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

mgzhenhong opened this issue Mar 21, 2025 · 5 comments

Comments

@mgzhenhong
Copy link

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?

@bbuechler
Copy link

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.

@mgzhenhong
Copy link
Author

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

@CharaD7
Copy link

CharaD7 commented Apr 29, 2025

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>

@mvk
Copy link

mvk commented Apr 29, 2025

@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?

@CharaD7
Copy link

CharaD7 commented Apr 29, 2025

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants