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

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달 전

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인