多伺服器mysql自動化執行sql

來源:互聯網
上載者:User

標籤:example   伺服器   master   linux   export   

先實現伺服器的root ssh互信,在master伺服器做如下操作

一、配置mysql伺服器ip列表如下,可自訂:

ceshi1      192.168.177.73     3358

ceshi2      192.168.177.73     3359

二、#linux批量串連多伺服器的shell指令碼如下:

#!/bin/bash

if [[ "$#" -lt "5" ]]

 then

     echo "error"

     echo "for example:$0 dbip.ini run.sql user pass db_name"

    exit 1

fi

name=(`cat /export/scripts/$1 | awk ‘{print$1}‘`)

ip=(`cat /export/scripts/$1 | awk ‘{print$2}‘`)

port=(`cat /export/scripts/$1 | awk ‘{print$3}‘`)

user=$3

pass=$4

db_name=$5

time=`date +%Y%m%d`

touch /export/scripts/$time.txt

len=${#ip[*]}

num=0

while [ $num -lt $len ]

do

  echo "===========  ${name[$num]}  ============="

  echo "===========  ${name[$num]}  =============" >> /export/scripts/$time.txt

  mysql -u$user -p$pass -h${ip[$num]} -P${port[$num]} $db_name  < $2

  let num++

done


本文出自 “雲淡風輕” 部落格,謝絕轉載!

多伺服器mysql自動化執行sql

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.