本文共 1283 字,大约阅读时间需要 4 分钟。
#!/usr/bin/env python# _*_ conding:utf-8 _*_import sysimport osimport timeimport datetimeimport MySQLdbbb=datetime.datetime.now()c_time=time.strftime("%Y%m%d",time.localtime(time.time()))today=datetime.date.today()oneday=datetime.timedelta(days=1)yesterday=today-onedayyes_last=datetime.datetime.strftime(yesterday,"%Y%m%d")print yes_last#print c_timetry: conn1=MySQLdb.connect(host='192.168.1.17',user='dlan',passwd='root123',port=3306,db='chat') conn2=MySQLdb.connect(host='192.168.1.17',user='dlan',passwd='root123',port=3306,db='test') cur1 = conn1.cursor() cur2 = conn2.cursor() aa1='''select * from chat.honghong1_'''+yes_last aa2 = "create table IF NOT EXISTS ip_limit_"+yes_last+" " +"(id int,name varchar(22),c_time datetime)" cur1.execute(aa1) bb=cur1.fetchall() cur2.execute(aa2) value=() for i in xrange(len(bb)): value=(bb[i]) db_insert="insert into"+' '+"ip_limit_"+yes_last +" "+ "values(%s,%s,%s)" cur2.execute(db_insert,value) print "OK" conn2.commit() print "--------" conn1.commit() cur1.close() cur2.close() conn1.close() conn2.close()except MySQLdb.Error,e: print "Could not connect to MySQL server",e
转载地址:http://wgzda.baihongyu.com/