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: