I am having trouble connecting to a mysql rds

0

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 Inbound Rule Settings

Publicly Accessible

1 個回答
0
已接受的答案

You say you have added a security group with multiple rules. If you mean you created one, then from your RDS screen shot it’s NOT configured to use this new security group. You’ll see RDS is using the default security group.

Other thing to note a public RDS instance needs to be in a Public subnet.

profile picture
專家
已回答 6 個月前
profile picture
專家
已審閱 2 個月前

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

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

回答問題指南