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 Answer
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
EXPERT
answered 6 months ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions