mysql全备份

#!/bin/bash
mkdir /backup
cd /backup
dateDIR=`date +"%y-%m-%d"`
mkdir -p $dateDIR/data
for i in `mysql -uroot -p123456 -e "show databases" | grep -v "Database"`
do
mysqldump -uroot -p123456 --default-character-set=gbk --opt $i | gzip > /backup/$dateDIR/data/${i}_${dateDIR}.sql.gz
done

binlog_rm=`tail -n 1 $path/mysql-bin.index | sed 's/.\///'`
mysql -uroot -p123456 -e "purge binary logs to '$binlog_rm'"

本文出自 “Android/Linux@HeFei” 博客,转载请与作者联系!

你可能感兴趣的:(mysql,数据库,职场,休闲)