简体   繁体   English

AWS RDS Postgres 与 Python 的连接

[英]AWS RDS Postgres Connection With Python

I'm trying to connect to a postgres db with python but i'm not sure of the connection logic.我正在尝试使用 python 连接到 postgres 数据库,但我不确定连接逻辑。 I have:我有:

host_name = "my_db-db.cluster-XXXXXX.us-east-1.rds.amazonaws.com"
username = "postgres"
dbname = "my_db"
password = "my_password"
port = "5678"

I've tried using:我试过使用:

from sqlalchemy import *
engine = 
create_engine('postgresql://postgres:my_password@localhost:5678/my_db')
engine.connect()

How do I adjust the engine term to establish a connection?如何调整引擎术语以建立连接?

Replace localhost with the RDS host name.localhost替换为 RDS 主机名。

from sqlalchemy import *
engine = 
create_engine('postgresql://postgres:my_password@my_db-db.cluster-XXXXXX.us-east-1.rds.amazonaws.com:5678/my_db')
engine.connect()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM