甜橘子,专注成都网站制作网站设计与营销型网站建设与优化
QQ :
532337155
电话:
028-86922220
首页
网站建设
网站制作案例
解决方案
网站设计报价
网站制作动态
关于我们
联系我们
成都网站建设设计
将想法与焦点和您一起共享
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://chengdu.cdxwcx.cn/article/picgog.html
其他资讯
生成随机数代码JAVA 产生随机数的代码java
c语言结构体做函数调用 c语言结构体如何调用
怎么修改域名所有者 域名所有人可以更改么
阿里云服务器能用学生续费 阿里云学生服务器续费多少钱
c语言获取键盘值的函数 c语言从键盘获取字符串
QQ咨询
在线咨询
官方微信
联系电话
座机
028-86922220
手机
13518219792
返回顶部