然后在slave服务器上停止数据同步
MySQL> stop slave;
在主从上各插入一条不同数据(供测试读的时候用):
在主上插入:insert into sxit values('1','zhangsan');
在从上插入:insert into sxit values('2','lisi');
登陆到amoeba服务器,进行读写分离的测试:
# mysql -u root -psxit -h10.10.0.87 -P8066
mysql> use test;
mysql> select * from sxit; //第一次执行select是在master服务器上查询的
+------+----------+
| id | name |
+------+----------+
| 1 | zhangsan |
+------+----------+
1 row in set (0.00 sec)
mysql> select * from sxit; //第二次执行select是在slave服务器上查询的
+------+------+
| id | name |
+------+------+
| 2 | lisi |
+------+------+
1 row in set (0.01 sec)
mysql> insert into sxit values('3','wangmazi'); //插入一条数据,然后在select
Query OK, 1 row affected (0.05 sec)
mysql> select * from sxit; //可以看到上面新插入的语句在master上了
+------+----------+
| id | name |
+------+----------+
| 1 | zhangsan |
| 3 | wangmazi |
+------+----------+
2 rows in set (0.00 sec)
mysql> select * from sxit; //slave服务器上是没有这条新的语句的,
+------+------+
| id | name |
+------+------+
| 2 | lisi |
+------+------+
1 row in set (0.00 sec)
权重的设置
在这里可能会想到,两台数据库服务器,一台主,一台从,按照上面的配置只能是主和从的读取比率是1:1,而写又全部在主上进行,这样主的压力就很大了,所以如果能让主和从的读设置权重,比如设置成1:3,这样就可以很好的解决主从不压力均衡的问题!通过研究确实可以!
配置就是将上面的读的池的配置更改一下:
将<property>server1,server2</property>更改成
<property>server1,server2,server2,server2</property>
mysql> select * from sxit;
+------+------+
| id | name |
+------+------+
| 2 | lisi |
+------+------+
1 row in set (0.00 sec)
mysql> select * from sxit;
+------+------+
| id | name |
+------+------+
| 2 | lisi |
+------+------+
1 row in set (0.01 sec)
mysql> select * from sxit;
+------+------+
| id | name |
+------+------+
| 2 | lisi |
+------+------+
1 row in set (0.00 sec)
mysql> select * from sxit;
+------+----------+
| id | name |
+------+----------+
| 1 | zhangsan |
| 3 | wangmazi |
+------+----------+
2 rows in set (0.00 sec)
//从以上的查询来看,select确实是安装1:3的比例来进行查询的.
Amoeba实现MySQL主从读写分离(3)
内容版权声明:除非注明,否则皆为本站原创文章。