• python3删除mysql上月分区数据(脚本)


    import datetime
    import pymysql
    import pymysql.cursors
    
    tables_schdule=["talbe1","table2","table3","table4","table5"]
    
    x = datetime.date.today().replace(day=1)
    y = datetime.timedelta(days=1)
    last_month = (x-y).strftime("%Y%m")
    #print(last_month)
    
    drop_tables=[]
    for i in range(5):
        drop_tables.append("ALTER TABLE {} TRUNCATE PARTITION P{};".format(tables_schdule[i],last_month))
    
    #print(drop_tables)
    
    connection=pymysql.connect('127.0.0.1','root','duzhaoqi2015','eos')
    
    try:
    #获取一个游标
        with connection.cursor() as cursor:
            # sql='select * from test'
            # cursor.execute(sql)
            for i in drop_tables:
                #print(i)
                cursor.execute(i)
            # for row in cursor.fetchall():
            #     print("ID:" + str(row[0]) + '  名字:' + row[1])
            # connection.commit()
    finally:
        connection.close()
  • 相关阅读:
    css资料汇总
    typescript 点滴
    vue-cli3点滴
    item2的使用方法推介
    rfc文档
    websocket
    g2
    常用的正则积累
    Vue-20190623点滴
    写一个webpackLoader
  • 原文地址:https://www.cnblogs.com/duzhaoqi/p/11451048.html
Copyright © 2020-2023  润新知