Windows Server regularly backs up mysql databases automatically
Windows Server regularly backs up mysql databases automatically _ MySQL
Back up the MySQL database and automatically package it every morning, and delete the backup files five days ago.
1. environment: windows server 2003 + Apache 2.0 + PHP5 + MySQL 4.0.26.
2. assume that the PHP installation directory is D:/php, and the MySQL installation directory is D:/mysql.
3. create the WinRAR directory in D:/php and copy WinRAR.exe and RARReg. KEY in the winrar installation directory to D:/php/WinRAR.
4. D:/php file mysql_backup.php:
/*/////////////////////////
# FileName: mysql_backup.php # Author: faisun # Website: http://www.hzhuti.com
////////////////////////*/
// Save the directory. the path must use a backslash. you need to manually create it. $ store_folder = 'd:/databse_backup ';
// User name and password
// This account must have the permission to operate [all] databases and files
// Otherwise, some databases cannot be backed up.
$ Db_username = "root"; $ db_password = ""; $ time = time (); $ nowdir = "$ store_folder //". date ("Ymd", $ time ). ""; if (file_exists ("$nowdir.rar") die ("File exists. /n "); @ mkdir ($ nowdir); mysql_connect (" localhost "," $ db_username "," $ db_password "); $ query = mysql_list_dbs (); while ($ result = mysql_fetch_array ($ query) {system (dirname (_ FILE __). '/.. /mysql/bin/mysqldump -- opt '. "$ result [Database]-u {$ db_username }". ($ d B _password? "-P {$ db_password }":""). "> $ nowdir // $ result [Database]. SQL "); echo" dumping database '$ result [Database]'... /n ";} echo"/nWinrar loading... /n "; system (dirname (_ FILE __). "// WinRAR // WinRAR.exe a-ep1-r-o +-m5-df/" $nowdir.rar/"" $ nowdir /""); // delete the file five days ago @ unlink ("$ store_folder //". date ("Ymd", $ time-86400*5 ). ". rar "); echo"/nOK! /N ";>
5. D:/php creates the file mysql_backup.bat, which contains only one sentence:
php.exe mysql_backup.php
6. double-click the bat file to run the task. if the file can be backed up, OK. Next, add the task plan.
7. add D:/php/mysql_backup to the task schedule. select daily as the time. based on the monitoring results of the server, the traffic is low every morning from 5 to 8. because some database cleanup operations are performed during the 5-7 period, the time can be set to eight o'clock in the morning.
For more details, see: http://www.111cn.net/sys/Windows/41837.htm
The above is the windows Server's regular automatic database backup for mysql database _ MySQL content, for more information, please follow the PHP Chinese network (www.php1.cn )!