#!/usr/bin/env python
# _*_ coding: utf-8 _*_
import pymysql
import time
db = pymysql.connect(host='xxxxx',user='xxx',password='xxx',database='__recycle_bin__')
#call dbms_recycle.show_tables();
#call dbms_recycle.purge_table('__innodb_10097');
#
cursor = db.cursor()
#cursor.execute('select version()')
#data = cursor.fetchone()
#print ("Database version : %s " % data)
cursor.execute('call dbms_recycle.show_tables();')
data = cursor.fetchall()
try:
for results in data:
RECYCLE_TABLE = []
DEST_DB = []
DEST_TABLE = []
###回收站中的表名
RECYCLE_TABLE.append(results[1])
####要恢复到的库名
DEST_DB.append(results[2])
###要恢复的表名
DEST_TABLE.append(results[3])
# print(RECYCLE_TABLE)
# time.sleep(1)
# print(f"删除前的数据库、表分别是 {DEST_DB},{DEST_TABLE}")
# print(f"回收站中的表名是 {RECYCLE_TABLE}")
##清空回收站中表的语句call dbms_recycle.purge_table('TABLE_NAME')
##恢复表语句call dbms_recycle.restore_table('RECYCLE_TABLE','DEST_DB','DEST_TABLE');
###如:call dbms_recycle.restore_table('__innodb_1063','testDB','testTable');
###成功清空回收站
for i in RECYCLE_TABLE:
cursor.execute(f"call dbms_recycle.purge_table('{i}')")
print(f"正在清空回收站{i}表")
# print(sql)
# cursor.execute(sql)
# db.commit()
except:
db.rollback()
db.close()
标签:dbms,DEST,cursor,清空,recycle,TABLE,polardb,回收站 From: https://www.cnblogs.com/chinaops/p/16985358.html