suffix = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f']
def get_data_from_db(database):
try:
conn = MySQLdb.connect(host = DB[database]['host'], port = DB[database]['port'], user="xxxxxxxxx", passwd="xxxxxxxxxxx", db=database, charset="utf8", connect_timeout=5)
cursor = conn.cursor()
for i in suffix :
for j in suffix :
try:
tale_name = "tb_%s%s" % (i, j)
sql = "SELECT xxxxxxxx FROM %s where xxxxxxxxxxx" % (tale_name)
if cursor.execute(sql) <= 0:
fp = open('err.log', 'a')
fp.write('err, ' + database + ',' + tale_name +'\n')
fp.close()
continue
fp = open('data/' + database + '.log', 'a')
for row in cursor.fetchall():
fp.write(str(row[0]) + '\n')
fp.close()
except Exception as e:
print(e)
except Exception as e:
print(e)
从mysql数据库集群中读取数据并保存
最新推荐文章于 2023-03-23 11:42:24 发布