设为首页 加入收藏

TOP

MySQL定时备份Windows主机
2014-11-24 03:18:42 来源: 作者: 【 】 浏览:2
Tags:MySQL 定时 备份 Windows 主机

  对于Windows主机

  ==============

  假想环境:

  MySQL 安装位置:C:MySQL

  论坛数据库名称为:bbs

  MySQL root 密码:123456

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

  程序代码

  @echo off

  C:MySQLinmysqladmin -u root --password=123456 shutdown

  C:MySQLinmysqldump --opt -u root --password=123456 bbs > D:db_backupbs.sql

  C:MySQLinmysqld-nt

  将以上代码保存为backup_db.bat

  然后使用Windows的“计划任务”定时执行该脚本即可。

  同时,可以用PHP的方式,完成:

  让MYSQL实现自动备份变成可能!

  1、编辑如下代码,并保存为backup.php,如果要压缩可以拷贝一个rar.exe:

  

  if ($argc != 2 || in_array($argv[1], array(--help, - ))) {

   >

  backup Ver 0.01, for Win95/Win98/WinNT/Win2000/WinXP on i32

  Copyright (C) 2000 ptker All rights reserved.

  This is free software,and you are welcome to modify and redistribute it

  under the GPL license

  PHP Shell script for the backup MySQL database.

  Usage:

  With the --help, or - options, you can get this help and exit.

  

  } else {

  $dbname = $argv[1];

  $dump_tool = "c:\mysql\bin\mysqldump";

  $rar_tool = "d:\php4\rar";

  @exec("$dump_tool --opt -u user -ppassword $dbname > ./$dbname.sql");

  @exec("$rar_tool a -ag_yyyy_mm_dd_hh_mm $dbname.rar $dbname.sql");

  @unlink("$dbname.sql");

  echo "Backup complete!";

  }

   >

  2、添加一个任务计划,在(如图2所示)这一步输入命令:

  D:php4php.exe -q D:php4ackup.php databasename

  3、时间设置为每天运行一次,然后运行这个任务。

  4、最后会在d:php4目录下生成一个以数据库名和当前时间组成的rar文件。

】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇MySQL数据库可以用任意ip连接访问.. 下一篇mysql的权限级别

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容:

·C++中智能指针的性能 (2025-12-25 03:49:29)
·如何用智能指针实现c (2025-12-25 03:49:27)
·如何在 C 语言中管理 (2025-12-25 03:20:14)
·C语言和内存管理有什 (2025-12-25 03:20:11)
·为什么C语言从不被淘 (2025-12-25 03:20:08)