::換成默認的gbk chcp 936 rem ******MySQL backup start******** @echo off ::若是沒有則建立數據庫文件夾 IF NOT EXIST "D:\db_backup" MD "D:\db_backup" ::刪除超過30天的備份 forfiles /p "D:\db_backup" /m *_backup_*.sql -d -30 /c "cmd /c del /f @path" ::定義時間 set data_time=%date:~0,4%%date:~5,2%%date:~8,2% ::定義mysqldump.exe所在目錄+mysqldump set "mysqldump=D:\program\mysql-5.7.21-winx64\bin\mysqldump" ::定義mysql鏈接 set "mysql_connect=--opt --single-transaction=TRUE --user=root --password=nyt@aA? --host=127.0.0.1 --protocol=tcp --port=3306 --default-character-set=utf8 --single-transaction=TRUE --routines --events" IF NOT EXIST "D:\db_backup\eucenter" MD "D:\db_backup\eucenter" %mysqldump% %mysql_connect% "eucenter" > D:\db_backup\eucenter\eucenter_backup_%data_time%.sql IF NOT EXIST "D:\db_backup\mlgl_bm" MD "D:\db_backup\mlgl_bm" %mysqldump% %mysql_connect% "mlgl_bm" > D:\db_backup\mlgl_bm\mlgl_bm_backup_%data_time%.sql IF NOT EXIST "D:\db_backup\mlgl_nyt" MD "D:\db_backup\mlgl_nyt" %mysqldump% %mysql_connect% "mlgl_nyt" > D:\db_backup\mlgl_nyt\mlgl_nyt_backup_%data_time%.sql IF NOT EXIST "D:\db_backup\sdnyt" MD "D:\db_backup\sdnyt" %mysqldump% %mysql_connect% "sdnyt" > D:\db_backup\sdnyt\sdnyt_backup_%data_time%.sql IF NOT EXIST "D:\db_backup\saiku" MD "D:\db_backup\saiku" %mysqldump% %mysql_connect% "saiku" > D:\db_backup\saiku\saiku_backup_%data_time%.sql IF NOT EXIST "D:\db_backup\GIS_dlkj" MD "D:\db_backup\GIS_dlkj" %mysqldump% %mysql_connect% "GIS_dlkj" > D:\db_backup\GIS_dlkj\GIS_dlkj_backup_%data_time%.sql IF NOT EXIST "D:\db_backup\ncpsc" MD "D:\db_backup\ncpsc" %mysqldump% %mysql_connect% "ncpsc" > D:\db_backup\ncpsc\ncpsc_backup_%data_time%.sql IF NOT EXIST "D:\db_backup\ncpscjyzt" MD "D:\db_backup\ncpscjyzt" %mysqldump% %mysql_connect% "ncpscjyzt" > D:\db_backup\ncpscjyzt\ncpscjyzt_backup_%data_time%.sql IF NOT EXIST "D:\db_backup\ncpzz" MD "D:\db_backup\ncpzz" %mysqldump% %mysql_connect% "ncpzz" > D:\db_backup\ncpzz\ncpzz_backup_%data_time%.sql IF NOT EXIST "D:\db_backup\njtg" MD "D:\db_backup\njtg" %mysqldump% %mysql_connect% "njtg" > D:\db_backup\njtg\njtg_backup_%data_time%.sql IF NOT EXIST "D:\db_backup\nykjfw" MD "D:\db_backup\nykjfw" %mysqldump% %mysql_connect% "nykjfw" > D:\db_backup\nykjfw\nykjfw_backup_%data_time%.sql IF NOT EXIST "D:\db_backup\nysczl" MD "D:\db_backup\nysczl" %mysqldump% %mysql_connect% "nysczl" > D:\db_backup\nysczl\nysczl_backup_%data_time%.sql IF NOT EXIST "D:\db_backup\nysthj" MD "D:\db_backup\nysthj" %mysqldump% %mysql_connect% "nysthj" > D:\db_backup\nysthj\nysthj_backup_%data_time%.sql @echo on rem %data_time% rem ******MySQL backup end******** ::pause