- 论坛徽章:
- 5
|
#coding=utf-8
import MySQLdb
conn = MySQLdb.connect(host='localhost',port = 3306,user='admin',passwd='admin',db='google')
cur = conn.cursor()
try:
create_tb_cmd='''
create table if not exists tmp.Video_2017bak
(id int(10) unsigned,
asset_id int(10) unsigned,
company_id int(10),
);
'''
cur.execute(create_tb_cmd)
finally:
insert_tb_cmd='''
insert ignore into tmp.Video_2017bak (select * from google.Video where created_at < date_sub(now(), interval 2 year));'''
delete_tb_cmd='''
delete from google.Video where created_at < date_sub(now(), interval 2 year);'''
cur.execute(insert_tb_cmd)
cur.execute(delete_tb_cmd)
cur.close()
conn.commit()
conn.close()
我想问一下在上面的语句中,conn.commit()是不是把上面的sql语句做为事务来提交?
|
|