无法连接到MySQL服务器(110)(AWS RDS实例)

时间:2015-04-17 18:38:19

标签: amazon-web-services mysql-python

我有这个代码连接到rds实例:

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"

但我有这个错误:

 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)")

你知道为什么我有这个错误吗?

1 个答案:

答案 0 :(得分:2)

你应该检查两点:

  1. EC2 Sequrety Group分配给您RDS。检查是否已为您的RDS SG打开了接收端口3306
  2. RDS PVC - 可能你有几个,并检查它是否属于你的EC2实例所在的VPC