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.