How to schedule a scheduled backup of MySQL under Windows

Source: Internet
Author: User
Tags command line current time backup

MySQL supports command line import Export data file, format is *.sql

1) Import:

Mysql-u User name-p password database name < file path \ filename

2) Export:

Mysqldump-u User name-p password Database name > file path \ filename

3) Real case

I am on the Windows 2003 Development Server, the implementation of a timed automatic backup

Generic filename, used by date and time. sql. Here's my *.bat batch file

A total of 3 lines:

First line, which means switch to D disk

The second line, locate the MySQL installation directory's Bin directory, so you do not need to set environment variables

The third line, export the *.sql file and use the current time as the filename, in the following format: Cold_20101026_1244.sql, representing the cold database, the backup file generated at 12:44 noon on October 26, 2010

D:

CD D:\Program files\mysql\mysql Server 5.1\bin

mysqldump-uroot-p123456 Cold > D:\mysql_data\cold_%date:~0,4%%date:~5,2%%date:~8,2%_%time:~0,2%%time:~3,2%.sql

Then, add the batch file to the Windows Task plan.

Click Control Panel > Task Scheduler > Add Task Schedule.

By the way to restore the code, to restore the time to manually build the database, by default, is not automatically create the database

D:

CD D:\Program files\mysql\mysql Server 5.1\bin

mysql-uroot-p147258369 Cold < D:\mysql_data\cold_20101026_1234.sql

The rest is done by following the wizard. My solution is not the best solution, just a common practice, Oracle Backup, you can do so, cross-platform, you need to add the script to the task plan.

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.