Python connection to rds mysql server

0

Here is my python code to connect to an rds mysql instance. I have ensured that connections are publicly accessible and have a security group named default_ that accepts all traffic from source 0.0.0.0/0. The code is giving the error Error: (2003, "Can't connect to MySQL server on 'database-2.cgsvu7bg7jl5.us-east-2.rds.amazonaws.com' (timed out)") I do not know what to do from here because I think it should be configured. Let me know if there are any steps I can take to debug.

import pymysql

Replace with your RDS instance details

host = 'database-2.extra_info.rds.amazonaws.com' user = 'admin' password = 'my_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()

1 Respuesta
0

Please check the contents of the document below.
https://repost.aws/knowledge-center/rds-connectivity-instance-subnet-vpc

Since the error is a timeout error, the VPC network ACL settings or security group settings may be incorrect, or RDS public access may not be enabled.

profile picture
EXPERTO
respondido hace 6 meses
  • How would I connect an existing vpc that has an internet gateway (currently using for an ec2 environment) to the rds?

No has iniciado sesión. Iniciar sesión para publicar una respuesta.

Una buena respuesta responde claramente a la pregunta, proporciona comentarios constructivos y fomenta el crecimiento profesional en la persona que hace la pregunta.

Pautas para responder preguntas