polardb清空回收站
#!/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()

分类:
oracle&pg&mysql
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· 葡萄城 AI 搜索升级:DeepSeek 加持,客户体验更智能
· 什么是nginx的强缓存和协商缓存
· 一文读懂知识蒸馏