#!/usr/bin/env python # -*- coding: utf-8 -*- import MySQLdb import os import sys import time currentDate=time.strftime('%Y%m%d',time.localtime()) def getConn(host,user,password,port): conn=MySQLdb.connect(host=host,user=user,passwd=password,port=int(port)) cur=conn.cursor() return cur #def execSql(cur,sql): # cur.execute(sql) # data=cur.fetchall() # return data def getDabase(cur): sql='''select table_schema,table_name from information_schema.tables where table_schema !="mysql" and table_schema !="information" and table_schema !="performance_schema" and table_schema !="information_schema"''' cur.execute(sql) data=cur.fetchall() return data def mysqlDump(basedir,host,user,password,port): dump=basedir +' '+'-h' +' '+host+' '+'-u'+' '+user+' '+'-p'+password+' '+'-P'+' '+str(port) for i in a: databases=i[0] table=i[1] dump1=dump+' '+databases+' '+table +' '+'>'+databases+'_'+table+'_'+currentDate+'.'+'sql' time.sleep(1) os.system(dump1) if __name__=="__main__": cur=getConn("192.168.1.114",'dlan','root123',3306) #sql="select user,host from mysql.user" #aa=execSql(cur,sql) a=getDabase(cur) aa=mysqlDump('/usr/local/mysql/bin/mysqldump','192.168.1.114','dlan','root123',3306)
MySQL分库分表备份
原创
©著作权归作者所有:来自51CTO博客作者DBAspace的原创作品,请联系作者获取转载授权,否则将追究法律责任
上一篇:influxdb用户权限篇
下一篇:PYTHON 多线程信号量
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章