conn = MySQLdb.connect(host='localhost',port = 3306,user='root',passwd='123456',db='google') cur = conn.cursor() conn.autocommit(1)
query_sql = "select id from google.Video where created_at < date_sub(now(), interval 1 year);" insert_sql = "insert ignore into tmp.Video_2017bak (select * from google.Video where id = %s);" delete_sql = "delete from google.Video where id = %s;" cur.execute(query_sql) dataList = cur.fetchall() aaa = np.array(dataList) ids = []
for i in range(len(aaa)): ids.append(aaa[i]) if (i+1)%100==0 : cur.executemany(insert_sql,ids) ids = [] cur.executemany(insert_sql,ids) ids = []
for i in range(len(aaa)): ids.append(aaa[i]) if (i+1)%100==0 : cur.executemany(delete_sql,ids) ids = [] cur.executemany(delete_sql,ids) ids = []