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)
可以看到几次插入的结果都落到了节点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)
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)