用python备份mysql数据库的脚本


#!/usr/bin/env python
#!/usr/bin/env python
#-*-coding:utf-8-*-
#MYSQL 备份脚本
importstring
importtime
importos
data_path ="/data/"
sql_user ="root"
sql_pwd ="123456"
sql_ip ="127.0.0.1"
all="--all-databases"
defmysql_backup():
backup_name =data_path+time.strftime('%Y%m%d')+'.sql'
sql_comm ='mysqldump %s -h%s -u%s -p%s > %s'%(all,sql_ip,sql_user,sql_pwd,backup_name)
printsql_comm
ifos.system(sql_comm) ==0:
print"数据库备份成功!"
else:
print"数据库备份失败!"
defmain():
SQL_backup =mysql_backup()
printSQL_backup
if__name__ =="__main__":
main()


你可能感兴趣的:(mysql,python,数据库备份)