MySQL备份python代码
import os, time, pymysql, shutilfrom apscheduler.schedulers.blocking import BlockingScheduler # 定时任务def getDatabaseNames(): """ 连接数据库 返回指定数据库的所有的表 """ conn = pymysql.connect(host='10.100.102.224', port=3316, db='indexdb', user='root', passwd='root') cur = conn.cursor() cur.execute('show tables;') tables = cur.fetchall() cur.close() conn.close() return tablesdef db_bf(path): """ 创建存储路径 并且备份指定数据库下的表 """ path = path.strip() path = path.rstrip("\\") if not os.path.exists(path): # 判断系统是否存在该路径 os.makedirs(path) # ,不存在则创建 tables = getDatabaseNames() for table in tables: try: tablename = table[0] #