返回顶部
首页 > 资讯 > 数据库 >5.6 MySql主从自动切换脚本
  • 356
分享到

5.6 MySql主从自动切换脚本

2024-04-02 19:04:59 356人浏览 安东尼
摘要

2015.07.17<br /> <br /> <br /> <div id="codeText" class="codeText&q

2015.07.17<br /> <br /> <br /> <div id="codeText" class="codeText"> <ol style="margin:0 1px 0 0;padding:5px 0pt;" start="1" class="dp-CSS none_number"> <li> <span style="color:#000000;">#<span style="color:#0000CC;">!</span><span style="color:#0000CC;">/</span>bin/bash<br /> </span> </li> <li> cat <span style="color:#0000CC;">&lt;</span><span style="color:#0000CC;">&lt;</span> README<br /> </li> <li> #####################################################################################################<br /> </li> <li> #Auther <span style="color:#0000CC;">:</span>zhanglin &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; #<br /> </li> <li> #Date <span style="color:#0000CC;">:</span> 2015<span style="color:#0000CC;">.</span>07<span style="color:#0000CC;">.</span>17 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;#<br /> </li> <li> #Step 1<span style="color:#0000CC;">:</span> point the slave IP &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;                                      #<br /> </li> <li> #Step 2<span style="color:#0000CC;">:</span> check the master <span style="color:#0000FF;">and</span> slave infORMation whether Good <span style="color:#0000FF;">for</span> change   &nbsp; &nbsp;             #<br /> </li> <li> #Step 3<span style="color:#0000CC;">:</span> stop old slave<span style="color:#0000CC;">,</span>then get new master binlog <span style="color:#FF0000;">name</span> <span style="color:#0000FF;">and</span> postation<span style="color:#0000CC;">,</span>then execute change master to #<br /> </li> <li> #Step 4<span style="color:#0000CC;">:</span> start slave<span style="color:#0000CC;">,</span><span style="color:#0000FF;">and</span> show whether change successed<span style="color:#0000CC;">. &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</span>&nbsp;#<br /> </li> <li> #####################################################################################################<br /> </li> <li> README<br /> </li> <li> User<span style="color:#0000CC;">=</span>root<br /> </li> <li> PW<span style="color:#0000CC;">=</span>123456<br /> </li> <li> read <span style="color:#0000CC;">-</span>p <span style="color:#FF00FF;">"-- Please input the slave IP:"</span> Slave<br /> </li> <li> Master<span style="color:#0000CC;">=</span><span style="color:#0000CC;">$</span><span style="color:#0000CC;">(</span>Mysql <span style="color:#0000CC;">-</span>u${User} <span style="color:#0000CC;">-</span>h${Slave} <span style="color:#0000CC;">-</span>p${PW} <span style="color:#0000CC;">-</span>e <span style="color:#FF00FF;">"show slave status \G;"</span><span style="color:#0000CC;">|</span>awk <span style="color:#FF00FF;">'/Master_Host/{print $2}'</span><span style="color:#0000CC;">)</span><br /> </li> <li> &nbsp;<span style="color:#0000FF;">if</span> <span style="color:#0000CC;">[</span> <span style="color:#0000CC;">-</span>n <span style="color:#FF00FF;">"${Master}"</span> <span style="color:#0000CC;">]</span><br /> </li> <li> then<br /> </li> <li> <span style="color:#0000FF;">echo</span> <span style="color:#0000CC;">-</span>e <span style="color:#FF00FF;">"--Master IP:${Master},Slave IP:${Slave}"</span><br /> </li> <li> M<span style="color:#0000CC;">=</span><span style="color:#0000CC;">$</span><span style="color:#0000CC;">(</span>mysql <span style="color:#0000CC;">-</span>u${User} <span style="color:#0000CC;">-</span>h${Master} <span style="color:#0000CC;">-</span>p${PW} <span style="color:#0000CC;">-</span>e <span style="color:#FF00FF;">"show master status;"</span><span style="color:#0000CC;">|</span>awk <span style="color:#FF00FF;">'NR==2{print $2}'</span><span style="color:#0000CC;">)</span><br /> </li> <li> S<span style="color:#0000CC;">=</span><span style="color:#0000CC;">$</span><span style="color:#0000CC;">(</span>mysql <span style="color:#0000CC;">-</span>u${User} <span style="color:#0000CC;">-</span>h${Slave} <span style="color:#0000CC;">-</span>p${PW} <span style="color:#0000CC;">-</span>e <span style="color:#FF00FF;">"show slave status \G;"</span><span style="color:#0000CC;">|</span>awk <span style="color:#FF00FF;">'/Read_Master_Log_Pos/{print $2}'</span><span style="color:#0000CC;">)</span><br /> </li> <li> <span style="color:#0000FF;">echo</span> <span style="color:#0000CC;">-</span>e <span style="color:#FF00FF;">"-- master pos:${M};slave pos is:${S}"</span><br /> </li> <li> &nbsp;<span style="color:#0000FF;">else</span><br /> </li> <li> <span style="color:#0000FF;">echo</span> <span style="color:#FF00FF;">"-- Slave IP input wrong,please input again ! "</span><br /> </li> <li> exit 1<br /> </li> <li> &nbsp;fi<br /> </li> <li> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#0000FF;">if</span> <span style="color:#0000CC;">[</span> <span style="color:#FF00FF;">"${M}"</span> <span style="color:#0000CC;">-</span><span style="color:#0000FF;">eq</span> <span style="color:#FF00FF;">"${S}"</span> <span style="color:#0000CC;">]</span><br /> </li> <li> then<br /> </li> <li> &nbsp;read <span style="color:#0000CC;">-</span>p <span style="color:#FF00FF;">"-- Master-Slave is accordance,input Yes to start changing:"</span> var<br /> </li> <li> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;case <span style="color:#FF00FF;">"$var"</span> <span style="color:#0000FF;">in</span><br /> </li> <li> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#0000CC;">[</span>Yy<span style="color:#0000CC;">]</span><span style="color:#FF0000;">es</span><span style="color:#0000CC;">)</span><br /> </li> <li> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;mysql <span style="color:#0000CC;">-</span>u${User} <span style="color:#0000CC;">-</span>h${Slave} <span style="color:#0000CC;">-</span>p${PW} <span style="color:#0000CC;">-</span>e <span style="color:#FF00FF;">"stop slave;reset slave;change master to master_host='';"</span><br /> </li> <li> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Pos<span style="color:#0000CC;">=</span><span style="color:#0000CC;">$</span><span style="color:#0000CC;">(</span>mysql <span style="color:#0000CC;">-</span>u${User} <span style="color:#0000CC;">-</span>h${Slave} <span style="color:#0000CC;">-</span>p${PW} <span style="color:#0000CC;">-</span>e <span style="color:#FF00FF;">"show master status;"</span><span style="color:#0000CC;">|</span>awk <span style="color:#FF00FF;">'NR==2{print $2}'</span><span style="color:#0000CC;">)</span><br /> </li> <li> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;File<span style="color:#0000CC;">=</span><span style="color:#0000CC;">$</span><span style="color:#0000CC;">(</span>mysql <span style="color:#0000CC;">-</span>u${User} <span style="color:#0000CC;">-</span>h${Slave} <span style="color:#0000CC;">-</span>p${PW} <span style="color:#0000CC;">-</span>e <span style="color:#FF00FF;">"show master status;"</span><span style="color:#0000CC;">|</span>awk <span style="color:#FF00FF;">'NR==2{print $1}'</span><span style="color:#0000CC;">)</span><br /> </li> <li> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;mysql <span style="color:#0000CC;">-</span>u${User} <span style="color:#0000CC;">-</span>h${Master} <span style="color:#0000CC;">-</span>p${PW} <span style="color:#0000CC;">-</span>e <span style="color:#FF00FF;">"stop slave;<br /> </span> </li> <li> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;change master to master_user='ideal',master_host='${Slave}',master_passWord='123456',master_log_file='${File}',master_log_pos=${Pos};<br /> </li> <li> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;start slave;"<br /> </li> <li> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#0000CC;">;</span><span style="color:#0000CC;">;</span><br /> </li> <li> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#0000CC;">*</span><span style="color:#0000CC;">)</span><br /> </li> <li> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#0000FF;">echo</span> <span style="color:#FF00FF;">"-- error input .... exit!"</span><br /> </li> <li> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#0000CC;">;</span><span style="color:#0000CC;">;</span><br /> </li> <li> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;esac<br /> </li> <li> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#0000FF;">echo</span> <span style="color:#FF00FF;">"-- changing, please wait 3s...."</span><br /> </li> <li> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#FF0000;">sleep</span> 3<br /> </li> <li> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#0000FF;">echo</span> <span style="color:#FF00FF;">"-- change successfull,the new master is:${Slave},new slave is ${Master}"</span><br /> </li> <li> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;SlaveiOStatus<span style="color:#0000CC;">=</span><span style="color:#0000CC;">$</span><span style="color:#0000CC;">(</span>mysql <span style="color:#0000CC;">-</span>u${User} <span style="color:#0000CC;">-</span>h${Master} <span style="color:#0000CC;">-</span>p${PW} <span style="color:#0000CC;">-</span>e <span style="color:#FF00FF;">"show slave status \G;"</span><span style="color:#0000CC;">|</span>awk <span style="color:#FF00FF;">'/Slave_IO_Running/{print $2}'</span><span style="color:#0000CC;">)</span><br /> </li> <li> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;SlaveSQLStatus<span style="color:#0000CC;">=</span><span style="color:#0000CC;">$</span><span style="color:#0000CC;">(</span>mysql <span style="color:#0000CC;">-</span>u${User} <span style="color:#0000CC;">-</span>h${Master} <span style="color:#0000CC;">-</span>p${PW} <span style="color:#0000CC;">-</span>e <span style="color:#FF00FF;">"show slave status \G;"</span><span style="color:#0000CC;">|</span>awk <span style="color:#FF00FF;">'/Slave_SQL_Running/{print $2}'</span><span style="color:#0000CC;">)</span><br /> </li> <li> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf <span style="color:#FF00FF;">"The new master is: \n Slave_IO_Running=${SlaveIOStatus}\n"</span><br /> </li> <li> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf <span style="color:#FF00FF;">"Slave_SQL_Running=${SlaveSQLStatus}\n"</span><br /> </li> <li> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#0000FF;">else</span><br /> </li> <li> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#0000FF;">echo</span> <span style="color:#FF00FF;">"node change failed please change again ! "</span><br /> </li> <li> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;exit 1<br /> </li> <li> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;fi </li> </ol> </div> <br /> <br />
您可能感兴趣的文档:

--结束END--

本文标题: 5.6 MySql主从自动切换脚本

本文链接: https://lsjlt.com/news/45797.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

猜你喜欢
  • 5.6 MySql主从自动切换脚本
    2015.07.17<br /> <br /> <br /> <div id="codeText" class="codeText&q...
    99+
    2024-04-02
  • redis自动主从切换
    127.0.0.1     7000     master127.0.0.1     7001     slave127.0....
    99+
    2024-04-02
  • Mysql 5.6 Master和Slave 主备切换
    --master/slave切换记录,用于后期查找 环境: master: rhel 6.6 mysql 5.6 192.168.15.101 salve: rhel 7.2 mysql 5.6 19...
    99+
    2024-04-02
  • MySQL主从切换
    MySQL主从切换基于传统主从切换:当主宕机之后,方法一:1、所有从上IO线程都会因为主宕机中断,此时,停止SLAVE IO_THREAD,等待SQL线程将relay log中的事件执行完成;2、选择Rea...
    99+
    2024-04-02
  • 京东MySQL数据库主从切换自动化
    1. 产生背景随着京东业务的高速增长,数据的重要性对于京东来说重要程度不说自明,在信息时代,数据有着比人们更大的力量,数据库的价值可见一斑,数据库的存在为人们提供了更快的查询,那么为了更好地做到数据库的高可...
    99+
    2024-04-02
  • MySQL5.7一主两从MHA自动切换
    这篇文章主要讲解了“MySQL5.7一主两从MHA自动切换”,文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习“MySQL5.7一主两从MHA自动切换”吧!数据库架...
    99+
    2024-04-02
  • redis主从+keepalived 高可用 自动切换
    一环境介绍 master:  172.168.1.69slave  : 172.168.1.57      VIP  &nbs...
    99+
    2024-04-02
  • mysql主从搭建切换
    环境: 172.30.249.156 percona5.6.27 主机名:tr-mysql 跑着生产环境的应用的虚拟机 192.168.129.153 percona5...
    99+
    2024-04-02
  • 怎么切换MySQL主从
    本篇内容介绍了“怎么切换MySQL主从”的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!一、在主库上把热数据立...
    99+
    2024-04-02
  • BAT脚本实现自动IP地址切换
    BAT自动IP地址切换脚本如下: @echo off color 3f mode con cols=80 lines=30 title 自动IP地址切换脚本 By 小强 if "%1...
    99+
    2024-04-02
  • 自动监控主从MySQL同步的SHELL脚本分享
    这篇文章主要介绍“自动监控主从MySQL同步的SHELL脚本分享”,在日常操作中,相信很多人在自动监控主从MySQL同步的SHELL脚本分享问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法,希望...
    99+
    2024-04-02
  • mysql主备自动切换如何设置
    要设置MySQL主备自动切换,可以使用MySQL Replication来实现主备复制和故障切换。以下是设置主备自动切换的步骤: ...
    99+
    2024-04-09
    mysql
  • mysql主备自动切换怎么实现
    要实现MySQL主备自动切换,可以使用MySQL Replication和MySQL Cluster来实现高可用性。以下是一种实现方...
    99+
    2024-04-09
    mysql
  • mysql5.5、5.6自动化安装脚本怎么写
    mysql5.5、5.6自动化安装脚本怎么写,很多新手对此不是很清楚,为了帮助大家解决这个难题,下面小编将为大家详细讲解,有这方面需求的人可以来学习下,希望你能有所收获。使用环境:①CentOS6 &...
    99+
    2024-04-02
  • MySQL主从切换怎么实现
    这篇文章主要介绍“MySQL主从切换怎么实现”,在日常操作中,相信很多人在MySQL主从切换怎么实现问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法,希望对大家解答”MySQL主从切换怎么实现”的疑惑有所帮助!接下来,请跟着小编...
    99+
    2023-07-02
  • PHP实现Oracle主从复制自动切换的方法
    随着互联网技术的不断发展,对于Web应用程序的高可用性和负载均衡性的要求越来越高。其中,数据库是Web应用程序中的重要部分,也是其中最容易成为瓶颈的部分。为了解决数据库的高可用性问题,主从复制已经成为了一种比较常见的解决方案。而PHP是We...
    99+
    2023-05-15
    PHP Oracle主从复制 自动切换
  • PHP实现Redis主从复制自动切换的方法
    Redis是一款非常流行的键值对存储数据库,在现代Web应用中扮演着至关重要的角色。为了保证Redis的高可用性和稳定性,通常需要使用主从复制的技术。同时,由于主节点故障时需要自动切换到备用节点,使得复制集群具有自我修复的能力。下面介绍PH...
    99+
    2023-05-16
    PHP Redis 主从复制
  • mysql主从切换的注意事项
    本篇内容介绍了“mysql主从切换的注意事项”的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成! 使用vip地...
    99+
    2024-04-02
  • k8s部署mysql主从怎么切换
    要实现Kubernetes下的MySQL主从切换,可以按照以下步骤进行操作: 首先,创建MySQL主从的Deployment和S...
    99+
    2023-10-27
    k8s mysql
  • Mysql主从状态监控脚本
    目标:对Mysql从库进行状态监控,如果从库复制异常就告警思路:1、首先查找Mysql从库的4个参数值(show slave status根据这个命令);分别是从库的IO线程、SQL线程、复制延迟时间(这个...
    99+
    2024-04-02
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作