#!/usr/bin/env python # _*_ conding:utf-8 _*_ import sys import os import time import datetime import MySQLdb today=datetime.date.today() oneday=datetime.timedelta(days=1) yesterday=today-oneday yes_last=datetime.datetime.strftime(yesterday,"%Y%m%d") #print yes_last #print c_time try: conn1=MySQLdb.connect(host='192.168.1.108',user='dlan',passwd='root123',port=3306,db='aa') cur1 = conn1.cursor() aa2 = "create table aa_" + yes_last + " " + "as" + " " + "select * from test" + " " + "where" + " " + "date_format" + "(ti,'%Y%m%d')" + "=" + yes_last old_del = "delete from test" + " " + "where" + " " + "date_format" + "(ti,'%Y%m%d')" + "=" + yes_last cur1.execute(aa2) cur1.execute(old_del) conn1.commit() cur1.close() conn1.close() except MySQLdb.Error,e: print "Could not connect to MySQL server",e
转载于:https://blog.51cto.com/dbaspace/1878674