#!/usr/bin/env python# -*- coding: utf-8 -*-import mysqldbimport osimport sysimport timecurrentdate=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 datadef 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 datadef 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)
This article is from the "DBSpace" blog, so be sure to keep this source http://dbspace.blog.51cto.com/6873717/1882096
MySQL Sub-database sub-table backup