本文实例讲述了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.234' identified by 'jppasswd';
/>flush privileges;
2、将master设置为只读
复制代码 代码如下:
mysql> set global read_/>Query OK, 0 rows affected (0.00 sec)
+---------------+-------+
+---------------+-------+
交互模式:
复制代码 代码如下:
#masterha_master_switch --master_state=alive --c/masterha/app1.cnf --new_master_host=10.1.1.231 --new_master_port=63306
或非交互模式:
复制代码 代码如下:
#masterha_master_switch --master_state=alive --c/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、主上执行:
复制代码 代码如下: