mysql数据库更新

时间:2021-07-13 07:24:45

ps:增加屏幕输出,显示执行每个服更新sql的状态

先创建DBaddress.txt,内容以ip:端口:名称方式保存,例如:

X.X.X.X:5001:main1

ImportSql.sh

#!/bin/bash
pwd=**********
DB=*******
dir=/opt/bak;
date=`date +%Y%m%d%H%M`
if [ ! -d $dir ];then mkdir -p $dir; fi
rm -rf $dir/*
cat DBaddress.txt |while read line
do
echo $line>temp
ip=`awk -F: '{print $1}' temp`
port=`awk -F: '{print $2}' temp`
name=`awk -F: '{print $3}' temp`
echo "$date import to server $name"
for i in *.sql
do
echo "$date import $i"
mysqldump -h$ip -P$port -p$pwd $DB --opt -R -E >${dir}/${date}_${name}.sql
mysql -h$ip -P$port -p$pwd $DB<$i
echo "$date OK"
done
echo "$date done"
done