python对mysql每个表备份

江枫思渺然 提交于 2019-12-24 14:52:10
import osimport pymysql as MySQLdbdef 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 tablesdef 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)
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!