用python从mysql数据库中得到account and passwd
时间:2006-03-18 来源:powerccna
用LR直接从mysql数据库中读数据来非常麻烦,需要装VC,或是用cywin造个东东出来,所以还是自己从写了个python脚本,让从本地文件里面读数据
import MySQLdb
host='10.0.0.3'
user='root'
passwd='1234'
database='DBname'
db=MySQLdb.connect(host, user, passwd,database)
cursor = db.cursor()
def getdata():
cursor.execute("SELECT RecipientAddresses,Keyword FROM messagestore")
initaccPasswd=open('d:\\testdata.dat','w')
initaccPasswd.write('phonenumber,passwd'+'\n')
initaccPasswd.close()
for result in cursor.fetchall():
phonenumber=str(result[0])[0:str(result[0]).find('/')]
passwd=str(result[1])
accPasswd=open('d:\\testdata.dat','a')
accPasswd.write(phonenumber+','+passwd+'\n')
accPasswd.close()