Automatic backup and restore method of MySQL Database

Source: Internet
Author: User
Tags mysql tutorial mysql database

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.

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.