I want to print all databases of 1 RDS and run a select query on it. Here, I am able to print all databases but want to run SELECT query on each database. Please suggest solution for it?
import boto.rds
import sys
import os
import MySQLdb
conn = boto.rds.connect_to_region("ap-southeast-1", aws_access_key_id='xxxx',aws_secret_access_key='xxx')
instances = conn.get_all_dbinstances()
db = instances[0]
print "%s %s" % (instances, db.endpoint)
I used this as a code, but its not working
host_name=db.endpoint
print host_name
db = MySQLdb.connect(host=host_name,user="dxx",passwd="xxx",db="xxx")
cursor = db.cursor()
cursor.execute("SHOW DATABASES")
db.commit()
numrows = int(cursor.rowcount)
for x in range(0,numrows):
row = cursor.fetchone()
if row[0].find('em') != -1:
print row[0]
sql="select * from row[0].T_USER where LoginId='%s'" % 'hello'
cursor.execute(sql)
results = cursor.fetchone()
print results[0]
db.endpoint, its returning you tuple, get hostname form that tuple.print host_namestatement ?