1、分库备份
[root@localhost mysql-backup]# cat db_bak.sh
#!/bin/bash
k_user=root
bak_password=123456
bak_path=/root/mysql-backup/
bak_cmd="-u$bak_user -p$bak_password"
exc_db="Database|information_schema|mysql|performance_schema|sys"
dbname=`mysql $bak_cmd -e "show databases"| egrep -v $exc_db`
for db in `echo $dbname`
do
[ -d $bak_path ] || mkdir -p $bak_path
mysqldump $bak_cmd -B $db | gzip > $bak_path/${db}_`date +$Y%m%d`.sql.gz
done
2、分表备份
[root@localhost mysql-backup]# cat tb_bak.sh
#!/bin/bash
k_user=root
bak_password=123456
bak_path=/root/mysql-backup/
bak_cmd="-u$bak_user -p$bak_password"
exc_db="Database|information_schema|mysql|performance_schema|sys"
db_name=`mysql $bak_cmd -e "show databases"| egrep -v $exc_db`
#echo $db_name
for db in `echo $db_name`
do
[ -d ${bak_path} ] || mkdir -p ${bak_path}
dt_name=`mysql $bak_cmd -e "use $db;show tables" | egrep -v "Tables_in_$db"`
#echo $db
#echo $dt_name
for dt in `echo $dt_name`
do
#echo $db $dt
mysqldump $bak_cmd $db ${dt} | gzip > $bak_path/${db}_${dt}.`date +%F%m%d`.sql.gz
done
done
3、运行截图
文章来源地址https://www.toymoban.com/news/detail-615313.html
文章来源:https://www.toymoban.com/news/detail-615313.html
到了这里,关于MySQL 实现分库和分表的备份 2023.7.29的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!