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