MySql regular backup database and MySql backup database

Source: Internet
Author: User
Tags mysql backup mysql backup database

MySql regular backup database and MySql backup database

Back up the database at every day, store the backup files in the specified directory (new if the directory does not exist), and store them on a monthly basis;

Store the following command as a *. bat file, add a Windows Task scheduler to point to this file, and execute it once a day.

rem *******************************Code Start*****************************@echo offC:CD C:\Program Files\MySQL\MySQL Server 5.7\binset "Y=%date:~10,4%"set "m=%date:~7,2%"set "d=%date:~4,2%"if not exist "D:\ARTS Backup\BK%Y%%m%\" (mkdir "D:\ARTS Backup\BK%Y%%m%\")mysqldump --opt -u root --password=ameroidrts ameroid > "D:\ARTS Backup\BK%Y%%m%\ameroid_%Y%%m%%d%.sql"@echo onrem *******************************Code End*****************************

 

Description

My MySql is installed in C: \ Program Files, so you must first enter the bin directory of MySql to execute the mysqldump command

C:CD C:\Program Files\MySQL\MySQL Server 5.7\bin

If your MySql is installed elsewhere, modify the drive letter and path.

 

I used the date: Command to get the current date. The following three commands get the year, month, and day respectively:

set "Y=%date:~10,4%"set "m=%date:~7,2%"set "d=%date:~4,2%"

Because my computer is in an English environment, you can use echo % date :~, 20% view the date format (output the first 20 characters of the date string)

If your computer environment is Chinese, the date format should be: 2016/03/09 Wednesday, that year, month, and day should be:

set "Y=%date:~,4%"set "m=%date:~5,2%"set "d=%date:~8,2%"

 

If not exist is used to determine whether a directory exists, mkdir is used to create a new directory, and if the directory name contains spaces, the entire path can be enclosed in double quotation marks.

 

Backup file storage 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.