32 lines
868 B
Python
32 lines
868 B
Python
import MySQLdb
|
|
|
|
conn = MySQLdb.connect(
|
|
host='gvsds.com', port=50030, user='root',
|
|
password='sajksh.sdfGH3YUge.wjkd+',
|
|
database='xaio_cheng_xu', charset='utf8mb4'
|
|
)
|
|
cur = conn.cursor()
|
|
|
|
# 获取所有表
|
|
cur.execute("SELECT TABLE_NAME FROM information_schema.TABLES WHERE TABLE_SCHEMA='xaio_cheng_xu'")
|
|
tables = [row[0] for row in cur.fetchall()]
|
|
print(f'共 {len(tables)} 张表')
|
|
|
|
# 禁用外键检查,删除所有表
|
|
cur.execute('SET FOREIGN_KEY_CHECKS = 0')
|
|
for t in tables:
|
|
cur.execute(f'DROP TABLE IF EXISTS `{t}`')
|
|
print(f' 已删除: {t}')
|
|
cur.execute('SET FOREIGN_KEY_CHECKS = 1')
|
|
|
|
conn.commit()
|
|
print(f'\n已删除全部 {len(tables)} 张表')
|
|
|
|
# 验证
|
|
cur.execute("SELECT COUNT(*) FROM information_schema.TABLES WHERE TABLE_SCHEMA='xaio_cheng_xu'")
|
|
count = cur.fetchone()[0]
|
|
print(f'剩余表数: {count}')
|
|
|
|
cur.close()
|
|
conn.close()
|