简体   繁体   中英

connecting to mysql db on amazon rds

I am using python's MySQLdb module on a windows 7 machine and trying to connect to a remote database on Amazon RDS (SQL Server Express). Here is the simple connection scheme I am using to establish a connection, but it never works:

import MySQLdb

cnx= {'host': 'dbname.xxxxxxxxxxxx.us-west-1.rds.amazonaws.com',
  'username': 'username',
  'password': 'password',
  'db': 'dbname'}

db = MySQLdb.connect(cnx['host'],cnx['username'],cnx['password'], cnx['db'])

When i execute this connection script, it waits for a few seconds (10 to 15 secs mostly) and then gives out the following error:

OperationalError: (2003, "Can't connect to MySQL server on 'dbname.xxxx.us-west-1.rds.amazonaws.com' (10060)")

I have used sql server on localhost previously, and used to connect it using the same scheme and it worked always. Now, this is the first time I am dealing with a db on amazon rds and have no idea why this error is showing up..please help. Thanks.

It's been 7 months and likely you have already figured out by now... That's probably because you have not added the IP of machine where you are connecting from to the security group of the RDS instance. First go to the RDS实例 details page, click on the link to the security group, then you should find at the 底部 of the page to add IP of your connecting host.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM