转载一下,方便以后应用
def center(sql):
try:
center_ip = '192.168.1.100'
center_user = 'root'
center_passwd = 'xxxxxx'
conn = MySQLdb.connect(host = center_ip,user = center_user,passwd = center_passwd,charset='utf8',connect_timeout=20)
cursor = conn.cursor()
cursor.execute(sql)
alldata = cursor.fetchall()
cursor.close()
conn.close()
return alldata
except:
return 0
虽然简单,但还挺实用的
原文地址http://wangwei007.blog.51cto.com/68019/1118809