您的位置
主页 > 网站技术 > 数据库 > » 正文

MHA实现mysql主从数据库手动切换的方法

来源: 锦尚中国 点击:

本文实例讲述了MHA实现mysql主从数据库手动切换的方法,分享给大家供大家参考。具体方法如下:

一、准备工作

1、分别在Master和Slave执行如下,方便mha检查复制:

复制代码 代码如下:

grant all privileges on *.* to 'root'@'10.1.1.231' identified by 'rootpass';
grant all privileges on *.* to 'root'@'10.1.1.234' identified by 'rootpass';
grant replication slave on *.* to 'jpsync'@'10.1.1.231' identified by 'jppasswd';
grant replication slave on *.* to 'jpsync'@'10.1.1.234' identified by 'jppasswd';
flush privileges;


2、将master设置为只读
 

复制代码 代码如下:

mysql> set global read_only=1;
Query OK, 0 rows affected (0.00 sec)
mysql> show variables like 'read_only';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| read_only     | ON    |
+---------------+-------+
1 row in set (0.00 sec)


交互模式:

复制代码 代码如下:

#masterha_master_switch --master_state=alive --conf=/etc/masterha/app1.cnf    --new_master_host=10.1.1.231  --new_master_port=63306


或非交互模式:

复制代码 代码如下:

#masterha_master_switch --master_state=alive --conf=/etc/masterha/app1.cnf    --new_master_host=10.1.1.231  --new_master_port=63306 —interactive=0

二、切换完以后,如何让10.1.1.231为主,10.1.1.234为从,操作步骤:

1、主上执行:

复制代码 代码如下:




首页  - 关于站长圈  - 广告服务  - 联系我们  - 关于站长圈  - 网站地图  - 版权声明