Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3.x 使用python连接到AWS RDS Postgres数据库_Python 3.x_Postgresql_Amazon Web Services_Amazon Rds - Fatal编程技术网

Python 3.x 使用python连接到AWS RDS Postgres数据库

Python 3.x 使用python连接到AWS RDS Postgres数据库,python-3.x,postgresql,amazon-web-services,amazon-rds,Python 3.x,Postgresql,Amazon Web Services,Amazon Rds,我在RDS中有一个现有的postgres表,其数据库名为my RDS表名 我已使用pgAdmin4通过以下只读用户配置连接到它: host_name = "my-rds-table-name.123456.us-east-1.rds.amazonaws.com" user_name = "my_user_name" password = "abc123def345" 我已经验证了我可以查询该表 但是,我无法使用python连接到它: SQLAlchemy==1.2.16 psycopg2-bi

我在RDS中有一个现有的postgres表,其数据库名为
my RDS表名

我已使用pgAdmin4通过以下只读用户配置连接到它:

host_name = "my-rds-table-name.123456.us-east-1.rds.amazonaws.com"
user_name = "my_user_name"
password = "abc123def345"
我已经验证了我可以查询该表

但是,我无法使用python连接到它:

SQLAlchemy==1.2.16
psycopg2-binary==2.7.6.1
mysqlclient==1.4.1
与:

它失败了

psycopg2.OperationalError: FATAL:  database "my-rds-table-name" does not exist
类似地,如果我尝试使用sqlalchemy连接到它:

sqlalchemy.exc.OperationalError: (psycopg2.OperationalError) FATAL:  database "my-rds-table-name" does not exist

我遗漏了什么?

感谢约翰·罗滕斯坦的评论


正如他指出的,
myrds表名
是数据库实例名,而不是数据库名,默认数据库名是
postgres

import psycopg2
engine = psycopg2.connect(
    database="postgres",
    user="my_user_name",
    password="abc123def345",
    host="my-rds-table-name.123456.us-east-1.rds.amazonaws.com",
    port='5432'
)

使用sqlalchemy,您可以执行以下操作:

engine = create_engine('postgresql://postgres:postgres@<AWS_RDS_end-point>:5432/postgres')

my rds table name
是数据库实例(服务器)的名称。在数据库实例中,有一个逻辑数据库,它没有名称
my rds table name
。您可以使用RDS控制台查找数据库的实际名称。
engine = create_engine('postgresql://postgres:postgres@<AWS_RDS_end-point>:5432/postgres')
df = pd.DataFrame({'A': [1,2], 'B':[3,4]})
df.to_sql('tablename', engine, schema='public', if_exists='append', index=False)