import pymysql
from os import system
from datetime import datetime
host = ' '
dbuser = ' '
password = ' '
dbname = ' '
# get tables name
conn = pymysql.connect(host=host, user=dbuser, password=password,db=dbname)
c = conn.cursor()
c.execute('SHOW TABLES')
tablelist = [ x[0] for x in c.fetchall() ]
c.close()
conn.close()
# mysqldump.exe backup (prefix_date)
prefix_date = str(datetime.today().date())
program = 'mysqldump.exe'
for table in tablelist:
command = '%s -h %s --user=%s --password=%s --tables %s %s > %s_%s_backup.sql' %(program,host,dbuser,password,dbname,table,prefix_date,table)
system(command)