Shell进行MySQL表跨服务器增量更新同步小脚本

数据中台工作所需写的小脚本

# !/bin/bash  
# Author    : yzz
# create_ts : 2022年 03月 16日 星期三 
# program   : Incremental transfer table records between MySQL servers
# crontab   : 11/min
#  
#  
# __init__  
host_src=yourht_A    # source db server config list
user_src=root
pswd_src=123
dbas_src=yourdb_A
#
host_tar=yourht_B    # target db server config list
user_tar=root
pswd_tar=456
dbas_tar=yourdb_B
#
cach_dump=/    # cache directory config
# 
# 
# define execute sql function
function sqlrun_src(){
mysql -h${host_src} -u${user_src} -p${pswd_src} <<EOF
$1
EOF
}
function sqlrun_tar(){
mysql -h${host_tar} -u${user_tar} -p${pswd_tar} <<EOF
$1
EOF
}
#  
#  
# do synchronize
tar_run="SELECT MAX(id) AS id FROM ${dbas_tar}.syn_tab;"
if id_ori=$(sqlrun_tar "${tar_run}") && id=${id_ori#id}
	then echo -e "\n\n …………Get Max id ${id}………… \n\n"
else exit && echo -e "\n\n …………Get Max id Failed………… \n\n"
fi
# 
src_run="SELECT * FROM ${dbas_src}.syn_tab WHERE id > ${i
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值