mysql> change master to master_host='192.168.1.5',master_user='libai',master_password='libai',master_port=3306,master_log_file='mysql-bin.000001',master_log_pos=0;
主库
1 2 3 4 5
# mysql -h localhost -ulibai -plibai mysql> createdatabase d; mysql> use d; mysql> createtable t(i int); mysql> insertinto t values(1);
从库
1 2 3 4 5
mysql> select * from t; +------+ | i | +------+ | 1 |
# mysql -h 192.168.1.2 -ulibai -p --port=4040 mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | d | | mysql | | performance_schema | | test | +--------------------+
登录admin查看状态
1 2 3 4 5 6 7 8 9
# mysql -h 192.168.1.2 -u admin -p --port=4041 mysql> select * from backends; +-------------+------------------+-------+------+------+-------------------+ | backend_ndx | address | state | type | uuid | connected_clients | +-------------+------------------+-------+------+------+-------------------+ | 1 | 192.168.1.5:3306 | up | rw | NULL | 0 | | 2 | 192.168.1.6:3306 | up | ro | NULL | 0 | +-------------+------------------+-------+------+------+-------------------+ 2 rows in set (0.00 sec)
可以从以上查询中看到master和slave状态均为up。
1)登录proxy节点,创建数据库dufu,并创建一张表t
1 2 3 4 5
mysql> createdatabase dufu; mysql> show databases; mysql> use dufu; mysql> createtable t(id int(10),namevarchar(20)); mysql> showtables;
创建完数据库及表后,主从节点上应该都可以看到
2)关闭同步,分别在master和slave上插入数据
mysql> slave stop;
master
mysql> insert into t values(1,'this_is_master');
slave
mysql> insert into t values(2,'this_is_slave');
3)proxy上查看结果
1 2 3 4 5 6 7 8
mysql> use dufu; mysql> select * from t; +------+---------------+ | id | name | +------+---------------+ | 2 | this_is_slave | +------+---------------+ 1 row in set (0.00 sec)
从结果可以看到数据是从slave上读取的,并没考虑master节点上的数据。
直接从proxy上插入数据
mysql> insert into t values(3,'this_is_proxy');
再次查询
1 2 3 4 5 6
mysql> select * from t; +------+---------------+ | id | name | +------+---------------+ | 2 | this_is_slave | +------+---------------+