Windows中Mysql计划任务备份数据库

两种备份命令基础知识

E:\>cd E:\wamp\bin\mysql\mysql5.0.51b\bin

E:\wamp\bin\mysql\mysql5.0.51b\bin>mysqldump -u root -p dx15>f:/dx15.sql

Enter password: ****

E:\wamp\bin\mysql\mysql5.0.51b\bin>mysqldump -u root -p””root”” dx15>F:\dx15.sql

第二种就是””不能少

 

还原命令

mysql -u root -p dx15< f:\dx15.sql

 

进入正题

MySQL 安装位置:红色第一行

数据库名称用户名密码:红色第二行前面

数据库备份目的地:D:\db_backup\

——————————————————

新建db_back.vbs,写入下列代码

Dim fName,tNow,CMD

tNow = Now()

fName = Year(tNow) & FormatNumber(Month(tNow)/100,2,false) & FormatNumber(Day(tNow)/100,2,false) & FormatDateTime(tNow,3)

fName = Replace(Replace(fName,”.”,””),”:”,””)

CMD = “”

CMD = CMD & “c:” & vbCrLf

CMD = CMD & “cd C:\Program Files\MySQL\MySQL Server 5.0\bin\” & vbCrLf

CMD = CMD & “mysqldump -u root -p””123456″” test>D:\db_backup\” & fName & “.sql”

Dim FileObject,BatFile,BatPath

Set FileObject = CreateObject(“Scripting.FileSystemObject”)

BatPath = “c:\backup.bat

Set BatFile = FileObject.CreateTextFile(BatPath, True)

BatFile.WriteLine(CMD)

BatFile.Close

Set BatFile = Nothing

Set FileObject = Nothing

Set WshShell = CreateObject(“Wscript.Shell”)

WshShell.Run BatPath,1,true

Set WshShell = Nothing

然后使用Windows的“计划任务”定时执行该批处理脚本即可。(例如:每天凌晨3点执行db_back.vbs)

 

引用资料详见

http://blog.sina.com.cn/s/blog_629b18b60100oux3.html

http://wenku.baidu.com/view/ecd362da6f1aff00bed51ec7.html

发表评论