本文实例讲述了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;
复制代码 代码如下:
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、主上执行:
复制代码 代码如下: