python对mysql每个表备份

import os
import pymysql as MySQLdb
def get_tb(sql):
conn = MySQLdb.connect(host="127.0.0.1",user="root",password="123",db="ccdb",charset='utf8')
cursor=conn.cursor()
cursor.execute(sql)
tables=[]
for i in cursor.fetchall():



tables.append(i[0])
cursor.close()
return tables
def baksqltab(tal):
password = "123"
ldn='ccdb'
for tab in tal:
os.system("E:\softwaremysql-5.6.39-winx64\mysql-5.6.39-winx64\bin\mysqldump.exe -uroot -p{} {} {} > E:\{}.sql".format(password,ldn,tab,tab))

if __name__ == '__main__':
sql="select table_name from information_schema.tables where table_schema='ccdb' and table_type='base table';"
tal=get_tb(sql)
baksqltab(tal)
原文地址:https://www.cnblogs.com/cheyunhua/p/12091443.html