postgresqlpsql

how to use “psql --dbname ”when password has kesword @


I want to use psql to exec ./my_test.sql(which is on my local windows) on linux pg.

I use --dbname to connect the db,but my password('z987xSst@@gres') has kesword "@" which leading a error like this:

psql --dbname=postgresql://postgres:z987xSst@@gres@ip:5432/postgres -A -t -q -f ./my_test.sql

-- psql: error: Unable to interpret host name "@gres@ip" to address: Unknown server error

I tried to use backslashes to do this (z987xSst\@\@gres), but it didn't work. I want to know what I need to do to make it work, or if there's another way. (Preferably, I don't have to enter the password manually, like --dbname str.)


Solution

  • You must encode the special characters, so @ becomes %40