主节点上:
mysql> show global status like '%Com_in%';
+--------------------+-------+
| Variable_name | Value |
+--------------------+-------+
| Com_insert | 13 |
| Com_insert_select | 0 |
| Com_install_plugin | 0 |
+--------------------+-------+
3 rows in set (0.00 sec)
从节点上:
mysql> show global status like '%Com_in%';
+--------------------+-------+
| Variable_name | Value |
+--------------------+-------+
| Com_insert | 13 |
| Com_insert_select | 0 |
| Com_install_plugin | 0 |
+--------------------+-------+
3 rows in set (0.00 sec)
写入insert:
mysql> insert into travelrecord(id,name)values(10000005,'ddd');
Query OK, 1 row affected (0.00 sec)
可以看到几次插入的结果都落到了节点192.168.1.250也就是master上
也可以使用show global status like ‘Com_insert’;查看主从mysql上的insert请求,如果两者都增加,说明请求分发到了主上,并复制到了从上,如果请求分发到了从上,那么就不会复制到主上,结果就是主上的这个状态变量不会增加,只有从上的这个状态变量会增加。
读操作
执行select之前
主节点:
mysql> show global status like 'Com_select';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| Com_select | 1334 |
+---------------+-------+
1 row in set (0.00 sec)
从节点:
mysql> show global status like 'Com_select';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| Com_select | 385 |
+---------------+-------+
1 row in set (0.00 sec)
执行select语句:
mysql> select * from travelrecord where id=1;
+----+------+------+
| id | name | age |
+----+------+------+
| 1 | aaa | NULL |
+----+------+------+
1 row in set (0.00 sec)
主节点:
mysql> show global status like 'Com_select';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| Com_select | 1334 |
+---------------+-------+
1 row in set (0.00 sec)
从节点:
mysql> show global status like 'Com_select';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| Com_select | 386 |
+---------------+-------+
1 row in set (0.00 sec)
都落在了hostS1也就是slave上
多测几次也是以上的效果,说明符合了balance=1的效果,读请求分发到了除主节点以外的节点(即从节点)。