我们专注攀枝花网站设计 攀枝花网站制作 攀枝花网站建设
成都网站建设公司服务热线:400-028-6601
网站建设
移动开发
小程序开发
运维推广
网站推广
网站推广
运维外包
运维外包
网站报价
经典案例
网站知识
关于我们
网站建设知识
十年网站开发经验 + 多家企业客户 + 靠谱的建站团队
量身定制 + 运营维护+专业推广+无忧售后,网站问题一站解决
5.6MySql主从自动切换脚本
2015.07.17
#
!
/
bin/bash
cat
<
<
README
#####################################################################################################
#Auther
:
zhanglin #
#Date
:
2015
.
07
.
17 #
#Step 1
:
point the slave IP #
#Step 2
:
check the master
and
slave information whether good
for
change #
#Step 3
:
stop old slave
,
then get new master binlog
name
and
postation
,
then execute change master to #
#Step 4
:
start slave
,
and
show whether change successed
.
#
#####################################################################################################
README
User
=
root
PW
=
123456
read
-
p
"-- Please input the slave IP:"
Slave
Master
=
$
(
MySQL
-
u${User}
-
h${Slave}
-
p${PW}
-
e
"show slave status \G;"
|
awk
'/Master_Host/{print $2}'
)
if
[
-
n
"${Master}"
]
then
echo
-
e
"--Master IP:${Master},Slave IP:${Slave}"
M
=
$
(
mysql
-
u${User}
-
h${Master}
-
p${PW}
-
e
"show master status;"
|
awk
'NR==2{print $2}'
)
S
=
$
(
mysql
-
u${User}
-
h${Slave}
-
p${PW}
-
e
"show slave status \G;"
|
awk
'/Read_Master_Log_Pos/{print $2}'
)
echo
-
e
"-- master pos:${M};slave pos is:${S}"
else
echo
"-- Slave IP input wrong,please input again ! "
exit 1
fi
if
[
"${M}"
-
eq
"${S}"
]
then
read
-
p
"-- Master-Slave is accordance,input Yes to start changing:"
var
case
"$var"
in
[
Yy
]
es
)
mysql
-
u${User}
-
h${Slave}
-
p${PW}
-
e
"stop slave;reset slave;change master to master_host='';"
Pos
=
$
(
mysql
-
u${User}
-
h${Slave}
-
p${PW}
-
e
"show master status;"
|
awk
'NR==2{print $2}'
)
File
=
$
(
mysql
-
u${User}
-
h${Slave}
-
p${PW}
-
e
"show master status;"
|
awk
'NR==2{print $1}'
)
mysql
-
u${User}
-
h${Master}
-
p${PW}
-
e
"stop slave;
change master to master_user='ideal',master_host='${Slave}',master_password='123456',master_log_file='${File}',master_log_pos=${Pos};
start slave;"
;
;
*
)
echo
"-- error input .... exit!"
;
;
esac
echo
"-- changing, please wait 3s...."
sleep
3
echo
"-- change successfull,the new master is:${Slave},new slave is ${Master}"
SlaveIOStatus
=
$
(
mysql
-
u${User}
-
h${Master}
-
p${PW}
-
e
"show slave status \G;"
|
awk
'/Slave_IO_Running/{print $2}'
)
SlaveSQLStatus
=
$
(
mysql
-
u${User}
-
h${Master}
-
p${PW}
-
e
"show slave status \G;"
|
awk
'/Slave_SQL_Running/{print $2}'
)
printf
"The new master is: \n Slave_IO_Running=${SlaveIOStatus}\n"
printf
"Slave_SQL_Running=${SlaveSQLStatus}\n"
else
echo
"node change failed please change again ! "
exit 1
fi
网页题目:5.6MySql主从自动切换脚本
网址分享:
http://mswzjz.cn/article/picgog.html
其他资讯
你了解Python中的递归吗
怎么在SpringBoot调用yml配置文件
mysql中表数据存放路径非datadir目录的示例分析
python炫酷烟花表白的源代码分享
“华三论剑”终尘埃落定广州华资摘得桂冠