数据库
首页 > 数据库> > 15行Shell解决按表备份mysql

15行Shell解决按表备份mysql

作者:互联网

databases='test1 test2'

Date=$(date "+%Y-%m-%d")
Time=$(date "+%H%M%S")

for db in $databases
	do mkdir -p `echo /home/backup/mysql/$db/$Date`
done

for db in $databases
	do tables=`mysql -u root -p123456 $db -e "show tables"`
	for table in $tables
		do mysqldump -u root -p123456 $db $table > /home/backup/mysql/$db/$Date/${table}_$Time.sql
	done
done

标签:tables,Shell,15,do,db,按表,done,mysql,Date
来源: https://www.cnblogs.com/sherlock-merlin/p/16293462.html