import pymysql
conn = pymysql.connect(host="127.0.0.1", user="root", password="root", charset="utf8")
cursor = conn.cursor(cursor=pymysql.cursors.DictCursor)
cursor.execute("SHOW DATABASES;")
databases = cursor.fetchall()
for i in databases:
cursor.execute(f"USE {i.get('Database')};")
cursor.execute("SHOW TABLES;")
tables = cursor.fetchall()
for table in tables:
for table_str in table.values():
try:
cursor.execute(f"select * from {table_str}")
data = cursor.fetchall()
with open(f"mysql/{table_str}.text", "w", encoding="utf-8") as f:
f.write(str(data))
except pymysql.err.OperationalError:
continue
标签:fetchall,execute,数据库,pymysql,cursor,str,table,数据,下载
From: https://www.cnblogs.com/chron/p/17623038.html