验证自动切换
停止当前主节点mysql服务
[root@HE3 conf]# cat dnindex.properties
#update
#Mon Sep 12 00:28:33 PDT 2016
localhost1=0
[root@HE3 conf]# /etc/init.d/mysqld stop
Shutting down MySQL............ SUCCESS!
观察dnindex.properties文件内容是否变化
[root@HE3 conf]# cat dnindex.properties
#update
#Mon Sep 12 18:32:28 PDT 2016
localhost1=1
当前可用节点只剩下原从节点,期望结果是之后的写入操作全部落到原从节点,验证:
mysql> insert into travelrecord values(3,'helei',25);
ERROR 1064 (HY000): partition table, insert must provide ColumnList
mysql> insert into travelrecord(id,name,age) values(3,'helei',25);
Query OK, 1 row affected (0.37 sec)
登录原从节点,观察数据变化:
mysql> use db1;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> show tables;
+---------------+
| Tables_in_db1 |
+---------------+
| travelrecord |
+---------------+
1 row in set (0.00 sec)
mysql> select * from travelrecord;
+---------+-------+------+
| id | name | age |
+---------+-------+------+
| 1 | aaa | NULL |
| 2 | asd | NULL |
| 3 | helei | 25 |
| 5000000 | bbb | 11 |
+---------+-------+------+
4 rows in set (0.00 sec)
说明此时写入节点已经切换为配置好的第二个writeHost,也就是原从节点,此时如果想要将原失败节点重新加入集群,需要重做主从,将原主节点作为从节点加入到集群中,mycat无需重启,对前端应用是透明的。