mysql的备份与还原
1、备份的BAT。获得当前日期作为文件名,到处数据后压缩删除源文件
echo off&setlocal enabledelayedexpansion
for /f "tokens=1-3 delims=-:/ " %%a in ("%date%") do (set Y=%%a&set M=%%b&set D=%%c&if "!M:~0,1!"=="0" set M=!M:~1!
if "!D:~0,1!"=="0" set D=!D:~1!)
set/a D-=1&if !D! leq 0 (set/a M-=1&if !M!==0 set/a Y-=1,M=12
set/a "T=^!(M-2)","R=(^!(Y%%4)&^!^!(Y%%100))|^!(Y%%400)","C=^!(M-4)|^!(M-6)|^!(M-9)|^!(M-11)","D=T*(28+R)+C*30+(^!T&^!C)*31"+D)
set M=0%M%&set D=0%D%
set mydate=%Y%%M:~-2%%D:~-2%
echo %mydate%
SET BAK_FILE=MY_DBBAK_"%mydate%".SQL
SET LOG_FILE=MY_DBBAK.log
echo "%mydate%" 》 %LOG_FILE%
mysqldump --default-character-set=utf8 -h192.168.1.1 -uroot -R -padmin --triggers --single-transaction -B dbname >%BAK_FILE%
rar a %BAK_FILE%.rar %BAK_FILE%
del %BAK_FILE%
echo "%mydate%" 》 %LOG_FILE%
echo "" 》 %LOG_FILE%
2、导入
mysql -uroot -p111111 dbname < aa.sql