MySQL Tutorial database Tutorial Automatic backup Restore method
Automatic Backup: Save the following code as a *.bat batch script, and then add Windows timed jobs, such as 2 o'clock in the morning daily:
Set s=%date:~0,4%%date:~5,2%%date:~8,2%%time:~1,1%%time:~3,2%%time:~6,2%
Mysqldump-u root-ppassword databasename > D:databasename_%s%_bak.sql
Note: DatabaseName for the database name password the database password, the system automatically backs up to the specified directory at the current date time.
Second, restore the database: mysql-u root-p databasename <d:databasename.sql
Backup Scenario One: a complete. sql file is generated directly through the mysqldump command.
Step 1: Create a batch
(Note: Root is the MySQL default user name, AAAAAA is the MySQL password, bugtracker is the database name)
------------Mysql_ Backup.bat--------------------------------------------------------------------------------------
D:
CD D:appservmysqlbin
MYSQLDUMP-UROOT-PAAAAAA bugtracker > E:databasemysql_bugtracker_backupbugtracker_back.sql
Exit
--------------------------------------------------------------------------------------------------------------- ---------
Step 2: Create a scheduled task
"Start"--> "Control Panel"--> "Administrative Tools"--> "Task Scheduler"
"Create a Basic Task"-->---> "daily" (note the time after setting)-->----"Start a program"--> "Browser" (Locate select the batch you just created Processing Mysql_backup.bat)-->---> "Finish"
The corresponding Restore method
To create a process:
----------Mysql_ Restore.bat-----------------------------------------------------------------------------------------
D:
CD D:appservmysqlbin
MYSQL-UROOT-PAAAAAA BugTracker < E:databasemysql_bugtracker_backupbugtracker_back.sql
Exit
--------------------------------------------------------------------------------------------------------------- ----------
Double-click it to automatically perform a restore
Backup scenario Two: Through the Xcopy command, directly to the MySQL data directory of the corresponding database all the files copy out
To create a batch process:
--------------------------------------------------------------------------------------------------------------- ---------------------------
xcopy D:appservmysqldatabugtracker e:databasemysql_bugtracker_backupbugtracker/e/h/d/y/r/v/f/k
Exit
--------------------------------------------------------------------------------------------------------------- ----------------------------
The corresponding Restore method
Copy the BugTracker folder in the E:databasemysql_bugtracker_backup directory directly to the D:appservmysqldata directory and cover all the BugTracker folders in the directory.