Reputation: 1337
I have this code to connect to a rds instance:
import MySQLdb
USERNAME = 'root'
PASSWORD = 'pass'
DB_NAME = 'databasetest2'
print "Connecting to RDS instance"
conn = MySQLdb.connect ( host = 'mysql-db-instance-database-test2.code.us-east-1.rds.amazonaws.com', user = USERNAME, passwd = PASSWORD, db = DB_NAME, port = 3306)
print "Connected to RDS instance"
But Im having this error:
Connecting to RDS instance
Traceback (most recent call last):
File "mysql.py", line 10, in <module>
conn = MySQLdb.connect ( host = 'mysql-db-instance-database-test2.code.us-east-1.rds.amazonaws.com', user = USERNAME, passwd = PASSWORD, db = DB_NAME, port = 3306)
File "/usr/lib/python2.7/dist-packages/MySQLdb/__init__.py", line 81, in Connect
return Connection(*args, **kwargs)
File "/usr/lib/python2.7/dist-packages/MySQLdb/connections.py", line 187, in __init__
super(Connection, self).__init__(*args, **kwargs2)
_mysql_exceptions.OperationalError: (2003, "Can't connect to MySQL server on 'mysql-db-instance-database-test2.code.us-east-1.rds.amazonaws.com' (110)")
Do you see why Im having this error?
Upvotes: 6
Views: 21643
Reputation: 77
The inability to connect to an Amazon RDS DB instance can have a number of root causes. Here are a few of the most common reasons :
The RDS DB instance is in a state other than available, so it can't accept connections.
The source you use to connect to the DB instance is missing from the sources authorized to access the DB instance in your security group, network access control lists (ACLs), or local firewalls.
The wrong DNS name or endpoint was used to connect to the DB instance.
The Multi-AZ DB instance failed over, and the secondary DB instance uses a subnet or route table that doesn't allow inbound connections.
The user authentication is incorrect.
Resolution :
For a more detailed guideline refer to this aws guide : https://aws.amazon.com/premiumsupport/knowledge-center/rds-cannot-connect/ You can also use the AWSSupport-TroubleshootConnectivityToRDS to troubleshoot your issue :https://docs.aws.amazon.com/systems-manager-automation-runbooks/latest/userguide/automation-awssupport-troubleshootconnectivitytords.html
Hopefully This will help you resolve your issue 😊
Upvotes: 0
Reputation: 2462
YOu should check two points:
Upvotes: 8