首先创建备份用户
create user "name"@"localhost" identified by "pass";
grant lock tables,reload,process,replication client,super,select,event,trigger,show view on *.* to "name"@"localhost" identified by "pass";
flush privileges;
接下来是一个全量备份的脚本=
#!/bin/bash
User=name
Pass=pass
BakDir=/data/mysql/backup
LogFile=/data/mysql/backup/bak.log
Date=`date "+%G-%m-%d_%H:%M:%S"`
cd $BakDir
DumpFile=$Date.sql
/mysql/bin/mysqldump -u$User -p$Pass --all-databases --flush-logs --single-transaction > $DumpFile 2>&1
find /data/mysql/backup -name "*.sql" -mtime +7 -exec rm -rf {} \;