MySQL scheduled backup Windows host

Source: Internet
Author: User
Keywords Web programming MySQL Tutorial
Tags backup code database backup environment forum help host installation

For Windows host

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

Hypothetical environment:

MySQL Installation Location: C:mysql

Forum database name: BBS

MySQL Root Password: 123456

Database backup destinations: D:db_backup

Program code

@echo off

C:mysqlbinmysqladmin-u Root--password=123456 shutdown

C:mysqlbinmysqldump--opt-u root--password=123456 bbs > D:db_backupbbs.sql

C:mysqlbinmysqld-nt

Save the above code as Backup_db.bat

You can then use Windows Scheduled Tasks to execute the script at timed intervals.

At the same time, you can use PHP to complete:

Let MySQL implement automatic backup become possible!

1, edit the following code, and save as backup.php, if you want to compress can copy a 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) Ptker All rights reserved.

This are free Software,and your are welcome to modify and redistribute it

Under the GPL license

PHP Shell script for the backup MySQL database.

Usage:

Can is database name you would like to backup.

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. Add a task plan, and in this step (shown in Figure 2), enter the command:

D:php4php.exe-q d:php4backup.php DatabaseName

3, the time is set to run once a day, and then run this task.

4, the final will be in the D:PHP4 directory to generate a database name and the current time composed of a RAR file.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.