Automatically backup the MySql database method on the Window system

  • 2020-05-14 05:07:10
  • OfStack

Under Window, Bat batch files can be used to backup MySql. In the case of large data volume, copy files can be used. However, this method requires the server to stop or stop writing commands, which is rarely used. If the data is small, it is recommended to use the mysqldump command to backup the database files as sql files. The use method is mysqldump, uroot, ppassword, dbname > db_date sql. A scheduled backup of the MySql database can be achieved by writing bat files and using window's task plan to periodically execute bat files. The Bat file 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 procedure above. echo off close the command line to execute output, echo output prompt messages, use set to set constants, and use rem to comment programs. Then switch to the bin directory of mysql and execute the mysqldump backup command. The backup databases are backed up by the database name and the current date. If you need to pause the program to see the result, use the pause command.

Related articles: