首页 > 数据库技术 > 详细

python对mysql每个表备份

时间:2019-12-24 15:51:57      阅读:124      评论:0      收藏:0      [点我收藏+]
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:\\software\mysql-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)

python对mysql每个表备份

原文:https://www.cnblogs.com/cheyunhua/p/12091443.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!