Automatic MySql database backup in Window System

Source: Internet
Author: User

In Windows, you can use Bat batch files to back up MySql. During backup, you can use the copy file mode when the data volume is large, however, this method requires the server to shut down or stop writing commands, which is not very useful. If the data is not big, we recommend that you use the mysqldump command to back up database files as SQL files. Use mysqldump-uroot-ppassword dbname> db_date. SQL. Compile the bat file and use the window task plan to regularly execute the bat file to implement regular backup of the MySql database. The Bat file is as follows: Copy codeThe Code is as follows: [html]
@ Echo off
Echo -------------------------
Echo mysql backup
Echo 2012.11.18
Echo -------------------------
Set year = % date :~ 0, 4%
Set month = % date :~ 5, 2%
Set day = % date :~ 8, 2%
Set scx_db = scx_db _ % year % month % day %. SQL
Set scxdb_db = scxdb_db _ % year % month % day %. SQL
Rem here is the comments section
Rem net stop mysql
Rem net start mysql
Cd D: \ Program Files \ phpStudy \ MySQL \ bin
Mysqldump-uroot-proot scx> d: \ bat \ % scx_db %
Mysqldump-uroot-proot scxdb> d: \ bat \ % scxdb_db %
Cd \
Cd bat
@ Echo off
Rem pause

Explain the above procedures. @ Echo off close command line execution output, echo output prompt information, use set to set constants, and use rem to annotate the program. Switch to the bin directory of mysql and run the mysqldump BACKUP command. The two backed up databases are backed up based on the database name and the current date. If you need to pause the program and see the result, use the pause command.

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.