分类: Mysql/postgreSQL
2018-06-25 14:57:25
脚本实现
#!/bin/bash
for db_name in `mysql -e "show databases;"|sed 1d`
do
mkdir -p /backup/$db_name
for table_name in `mysql -e "show tables from $db_name"|sed 1d`
do
/application/mysql/bin/mysqldump --master-data=2 $db_name $table_name >>/backup/$db_name/$(date +%F)$table_name.sql
done
done
1)先取出MySQL所有库的名称
2)用for循环便利每个库
3)再便利每个库中的每个表
4)然后通过mysqldump进行备份