import pymysql
Database connection parameters
endpoint = 'my-endpoint' # your RDS endpoint
username = 'admin' # your RDS username
password = 'my-password # your RDS password
Establish a database connection
try:
connection = pymysql.connect(host=endpoint, user=username, passwd=password)
cursor = connection.cursor()
# Create a new database
cursor.execute("CREATE DATABASE test;")
print("Database 'test' created successfully.")
except pymysql.MySQLError as e:
print(f"Error connecting to MySQL Database: {e}")
finally:
# Close the connection
if connection:
connection.close()
I am running this simple code and getting the error Error connecting to MySQL Database: (2003, "Can't connect to MySQL server on 'my-server-endpoint' (timed out)")
I have ensured that the db is publicly accessible and have added a security group that has multiple rules including accepting all traffic, accepting all ipv4 mysql/aurora connections and all ipv6 mysql/aurora connections.
Here are images of my security settings and my publicly accessible section
I have checked the 'default (sg-etc) security group and it does have the inbound rules that I have specified. How would I make sure that the rds is in a public subnet?
When you create your subnet group in RDS you define which subnets are part of the group. Check that the subnets in the database subnet group are correct. (Public) https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/USER_VPC.WorkingWithRDSInstanceinaVPC.html#USER_VPC.Subnets