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 個月前

您尚未登入。 登入 去張貼答案。

一個好的回答可以清楚地回答問題並提供建設性的意見回饋,同時有助於提問者的專業成長。

回答問題指南