SQLAlchemy error connecting to Google Cloud SQL with proxy

638 views Asked by At

system: ubuntu

  • Cloud sql instance: db
  • Cloud sql user: admin
  • Cloud sql pass: pass
  • cloud sql db name: test

cloud_sql_proxy installed and executed by ./cloud_sql_proxy -dir=/cloudsql -instances=prj:asia-northeast1:db -credential_file=path/to/credential

The account in the credential file has all needed roles, and successfully connected to the db from a nodejs server (typeorm).

But with sqlalchemy, I tried

sqlalchemy.create_engine("postgresql+psycopg2://admin:pass@/test?host=/cloudsql/prj:asia-northeast1:db")

and

sqlalchemy.create_engine("postgres+pg8000://admin:pass@/test?unix_sock=%2Fcloudsql%2Fprj%3Aasia-northeast1%3Adb%2F.s.PGSQL.5432")

but both complains about FATAL: password authentication failed for user "admin"

What have I did wrong?

1

There are 1 answers

0
marian.vladoi On

This error states that the db user and db password that you are using to connect to Cloud SQL server is wrong.

I would recommend to create a new Cloud SQL user and password and try again.

Creating and managing MySQL users

If you succeed with the new user, this will confirm my first hypothesis.