mysql5.6 分表分库脚本

教程发布:风哥 教程分类:ITPUX技术网 更新日期:2022-02-12 浏览学习:641

[backcolor=inherit]Mysql基于mysqldump的分库备份脚本
#!/bin/bash
db_user='root'
db_passwd=123456
db_host=192.168.2.88
db_none="information_schema|mysql|performance_schema"
db_command=`mysql -u$db_user -p$db_passwd -h $db_host -e "show databases;" |sed '1d' |egrep -v $db_none`
db_dump="mysqldump -u$db_user -p$db_passwd -h $db_host --master-data=2 --flush-logs --lock-all-tables"
db_file='/mydata/mysqlbak'
if [ ! -d $db_file ];then
mkdir -p $db_file
fi
for i in $db_command;
do
$db_dump $i |gzip > $db_file/${i}_$(date +%F-%H-%M-%S).sql.gz
done
(注意:db_passwd db_host 是远程授权过的账号和密码 估计要有复制权限 replication slave)

Mysql基于mysqldump的分表备份脚本

#!/bin/bash
db_user=root
db_passwd=123456
db_host=192.168.2.8
db_none="information_schema|mysql|performance_schema"
db_connect="mysql -u$db_user -p$db_passwd -h $db_host"
db_command=`mysql -u$db_user -p$db_passwd -h $db_host -e "show databases;" |sed '1d' |egrep -v $db_none`
db_dump="mysqldump -u$db_user -p$db_passwd -h $db_host --master-data=2 --flush-logs --lock-all-tables"
db_file='/mydata/mysqlbak'

if [ ! -d $db_file ];then
mkdir -p $db_file
fi
for db in $db_command
do
if [ ! -d $db_file/$db ];the
mkdir -p $db_file/$db
fi
for table in `$db_connect -e "show tables from $db;"|sed '1d'`
do
$db_dump $db $table |gzip > $db_file/${db}/${table}_$(date +%F-%H-%M-%S).sql.gz
done
done

本文标签:
网站声明:本文由风哥整理发布,转载请保留此段声明,本站所有内容将不对其使用后果做任何承诺,请读者谨慎使用!
【上一篇】
【下一篇】