MySQL timed backup Windows Host

Source: Internet
Author: User

For Windows Hosts

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

Hypothetical environment:

MySQL installation path: C: MySQL

Forum Database Name: bbs

MySQL root Password 123456

Database Backup destination: D: db_backup

Program code

@ Echo off

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

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

C: MySQLinmysqld-nt

Save the preceding code as backup_db.bat.

Then, run the script periodically using the "scheduled task" of Windows.

You can also use PHP to complete the following steps:

Make it possible for MYSQL to implement automatic backup!

1. Edit the code below and save it as backup.php. If you want to compress the code, you can copy 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:

Can be database name you wowould 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 mongodbname.rar $ dbname. SQL ");

@ Unlink ("$ dbname. SQL ");

Echo "Backup complete! ";

}

?>

2. Add a task scheduler and enter the following command in step (2:

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

3. Set the time to run the task once every day and then run the task.

4. An rarfile consisting of the Database Name and current time will be generated in the d: php4 directory.

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.