Automatic backup of MySQL database every day under win2003

  
                  Finally, let the server back up the MySQL database every morning and automatically package it, and delete the backup files 5 days ago. Share as follows.
1. Environment: windows server 2003 + Apache 2.0 + PHP5 + MySQL 4.0.26 .
2 Suppose the PHP installation directory is D:/php and the MySQL installation directory is D:/mysql.
3. Create a directory WinRAR under D:/php, copy WinRAR.exe and RARReg.KEY in your winrar installation directory. To D:/php/WinRAR.//This article comes from the computer software and hardware application network www.45it.com
4. D:/php create the file mysql_backup.php:

/*/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////*///Save the directory, the path should use a backslash. You need to create it manually. $store_folder = 'D:\\databse_backup'; //Username and password //The account must have access to [all] database and FILE permissions //otherwise some databases can not be backed up. $db_username = "root"; $db_password = ""; $time=time(); $ Nowdir = "$store_folder\\\\".date("Ymd",$time).""; if(file_exists("$nowdir.rar ")) die("File exists.\ "); @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} ".($db_password?"-p {$db_password}":"")." >$nowdir\\\\$result[Database].sql"); echo "dumping database `$result[Database]`...\ "; } echo "\ Winrar Loading...\ "; system( dirname(__FILE__)."\\\\WinRAR\\\\WinRAR.exe a -ep1 -r -o+ -m5 -df \\"$nowdir.rar\\" "$nowdir\\" " ) ; //Remove the file @unlink("$store_folder\\\\".date("Ymd",$time-86400*5).".rar"); echo "\ OK!\ "; > 5. Create a file mysql_backup.bat under D:/php, the content is only one sentence: //This article comes from the computer software and hardware application network www.45it.com

php.exe mysql_backup.php6. Double click the bat The file runs, if it can be backed up, OK, add the task plan in the next step. 
7. Add D:/php/mysql_backup to the mission plan, time to choose every day. According to the monitoring results of the server, every morning 5-8 hours flow Peak due to clean-up 5-7 when some databases, you can make it at the 8:00 o'clock.

Copyright © Windows knowledge All Rights Reserved