1、编写相关的备份脚本backup.bat:
@echo off
mysqldump -uroot -pXXX test>D:\db_backup\test%date:~0,10%.sql
其中“%date:~0,10%”表示取出日期后截取前10个字符,因为在目标机器运行%date%得到的是“2010-10-13 星期三”,不符合要求。
2、执行过程中,报如下错误:
mysqldump: Got error: 1045: Access denied for user:
'root@localhost ' (Using password: NO) when trying to connect
原因是权限不够,处理措施如下:
C:\Documents and Settings\Administrator.SPARK001>mysql -uroot -pXXX
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1450
Server version: 5.0.67-community MySQL Community Edition (GPL)
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%'IDENTIFIED BY 'root' WITH GRANT OPTION;
Query OK, 0 rows affected (0.06 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
3、运行bat文件后,即生成了“test2010-10-13.sql”类的文件,最后通过设置WINDOWS系统工具中的任务计划功能,即可实现自动备份。