版本1
rem ---move old bakupfile to tmp folder /y means no prompt ---
if not exist "D:\bak\tmp" md "D:\bak\tmp"
move /y D:\bak\mysqlbak D:\bak\tmp
if not exist "D:\bak\mysqlbak" md "D:\bak\mysqlbak"
rem ----------------------------------------------------------
rem ---use mysqldump dump database to sql---
c:
cd "C:\Program Files\MySQL\MySQL Server 5.7\bin"
mysqldump -uroot -proot portal > D:\bak\mysqlbak\%date:~0,4%%date:~5,2%%date:~8,2%.sql
rem ---del old backupfile in D:\bak\tmp
rd /s /q D:\bak\tmp\
版本2
@echo off
d:
cd D:\bak\mysqlbak\
del mysqldata2.sql
ren mysqldata1.sql mysqldata2.sql
ren mysqldata.sql mysqldata1.sql
c:
cd "C:\Program Files\MySQL\MySQL Server 5.7\bin"
mysqldump -uroot -proot portal > D:\bak\mysqlbak\mysqldata.sql
远程dump语法:
mysqldump -uUSERNAME -pPASSWORD -h 192.168.0.1 DATABASE TABLENAME > /localpath/datafile.sql
linux版本:
DATE=`date + %Y%m%d_%H%M%S`
mv /home/mysqldata/data/* /home/mysqldata/tmp
$MYSQLBIN/mysqldump --opt -uroot -ppwd dbname > /home/mysqldata/data/dbname_$DATE.sql
rm -rf /home/mysqldata/tmp
网友评论