手机
当前位置:查字典教程网 >脚本专栏 >python >Python Mysql自动备份脚本
Python Mysql自动备份脚本
摘要:测试系统环境Windows2003python2.5.1mysql5.0.1应该只适用于Win,因为调用了CMD。增量备份,因为自用,数据库...

测试系统环境Windows2003python2.5.1mysql5.0.1

应该只适用于Win,因为调用了CMD。

增量备份,因为自用,数据库不大。

回头有了需求加上自检测,5天前的自动删除。

#!/usr/bin/envpython

#encoding=utf-8

#Mysqlautobackup

#Author:vane

importos,sys,datetime

reload(sys)

sys.setdefaultencoding('utf-8')

backup_path="""d:mysql_backup_files"""

dbhost="localhost"

dbname="dabatasename"#数据库名

dbuser="root"#用户名

dbuserpw="123456"#密码

dbcharset='utf8'#输出文件编码,默认UTF8

now=str(datetime.datetime.now())[:10]

backup_command="""mysqldump-B%s-h%s-u%s-p%s--default_character-set=%s--opt>%sdbbackup_%s_%s.sqln"""%(dbname,dbhost,dbuser,dbuserpw,dbcharset,backup_path,dbname,now)

a,b=os.popen2('cmd')

a.write(backup_command)

a.close()

b.read()

b.close()

print"Done!"

【Python Mysql自动备份脚本】相关文章:

python操作MySQL数据库具体方法

Python subprocess模块学习总结

Python 面向对象 成员的访问约束

Python设计模式之单例模式实例

Python下的Mysql模块MySQLdb安装详解

使用Python进行稳定可靠的文件操作详解

使用python检测手机QQ在线状态的脚本代码

Python 调用VC++的动态链接库(DLL)

python之模拟鼠标键盘动作具体实现

python检测服务器是否正常

精品推荐
分类导航