RDS Mysql not connecting to python

0

I am trying to connect to python and this is the code I am using import pymysql

Replace with your RDS instance details host = 'database-2..rds.amazonaws.com' user = 'admin' password = ' ' database = 'test'

try:

Establish a connection to the database

connection = pymysql.connect(host=host, user=user, password=password, database=database)

Create a cursor object to interact with the database

with connection.cursor() as cursor: # Execute SQL queries or database operations here

# Example: Execute a SELECT query
cursor.execute("SELECT * FROM your_table_name")
results = cursor.fetchall()
for row in results:
    print(row)

except Exception as e: print("Error: {}".format(e))

finally:

Close the database connection when done

connection.close()

I am getting the error Error: (2003, "Can't connect to MySQL server on 'database-2.us-east-2.rds.amazonaws.com' (timed out)")

I have a vpc called db-vpc with a route from destination (0.0.0.0/0) to target an internet gateway called db-igw which is also attached to to the db-vpc. I then have an rds connected to db-vpc that is publicly accessible and has a vpc security group called default_ which contains an inbound rule of type all traffic from source 0.0.0.0/0

已提问 6 个月前290 查看次数
1 回答
0

Hello.

What are the public access settings for RDS?
Could you please share an image of your RDS public access settings?
If the RDS public access setting is disabled, please enable it.
https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/USER_VPC.WorkingWithRDSInstanceinaVPC.html#USER_VPC.Hiding

Also, please share the RDS security group settings with images.

Please check if there are any other settings on your local network router or firewall that would deny connections to MySQL.

profile picture
专家
已回答 6 个月前

您未登录。 登录 发布回答。

一个好的回答可以清楚地解答问题和提供建设性反馈,并能促进提问者的职业发展。

回答问题的准则