首页 > 代码库 > MySQL备份数据库脚本

MySQL备份数据库脚本

Windows
@echo off
mysqldump --add-drop-database --add-drop-table -u root -p123456 dbname > d:\db_backup\%date:~0,4%-%date:~5,2%-%date:~8,2%_%time:~0,2%-%time:~3,2%-%time:~6,2%_dbname.sql

Linux
#!/bin/sh
cd /usr/bin
DATE=`date +%Y-%m-%d`
# 备份dbname数据库
/usr/local/mysql/bin/mysqldump -uusername -ppassword dbname >/wwwroot/backup/$DATE.sql
cd /wwwroot/backup
#tar -zcvf $DATE.tar.gz $DATE.sql
zip -rP compress_password dbname_$DATE.zip $DATE.sql
rm -f $DATE.sql


来自为知笔记(Wiz)