Verifying HA
- Simulate a scenario where a secondary node is stopped and test read requests.
- Log in to secondary database 1.
/usr/local/mysql/bin/mysql -uroot -p123456 -S /data/mysql/run/mysqls.sock
- Stop the database.
shutdown;
- Log in to the primary database and view the group member information.
/usr/local/mysql/bin/mysql -uroot -p123456 -S /data/mysql/run/mysqlm.sock select * from performance_schema.replication_group_members;

- Execute the read request script.
sh /home/read_6447.sh

The 127.0.0.1:3307 database service is stopped. Connections to the read port are routed only to 127.0.0.1:3308 as expected.
- Log in to secondary database 1.
- Simulate a scenario where two secondary nodes are stopped and test the routing of read requests.
- Log in to secondary database 2.
/usr/local/mysql/bin/mysql -uroot -p123456 -S /data/mysql/run/mysqls2.sock
- Stop the database.
shutdown;
- Log in to the primary database and view the group member information.
/usr/local/mysql/bin/mysql -uroot -p123456 -S /data/mysql/run/mysqlm.sock select * from performance_schema.replication_group_members;

- Execute the read request script.
sh /home/read_6447.sh

Both secondary servers are stopped. Connections to the read port are routed to the primary node (127.0.0.1:3306) as expected (implemented by using the round-robin-with-fallback algorithm).
- Log in to secondary database 2.
- Simulate a primary role switchover.
- Start secondary databases 1 and 2.
/usr/local/mysql/bin/mysqld_safe --defaults-file=/etc/my.cnf-slave-mgr & /usr/local/mysql/bin/mysqld_safe --defaults-file=/etc/my.cnf-slave-2-mgr &
- Log in to secondary databases 1 and 2.
/usr/local/mysql/bin/mysql -uroot -p123456 -S /data/mysql/run/mysqls.sock /usr/local/mysql/bin/mysql -uroot -p123456 -S /data/mysql/run/mysqls2.sock
- Execute the following statement in secondary databases 1 and 2 separately to start MGR:
START GROUP_REPLICATION;
- View the information about group members. You can view any member in the MGR group.
select * from performance_schema.replication_group_members;

- Configure secondary database 2 as the primary and the other two databases as the secondaries.
select group_replication_set_as_primary ('member_id of secondary database 2');
- Execute the read request script.
sh /home/read_6446.sh

- Execute the write request script.
- Open the file.
vim /home/write_6446.sh
- Replace the file content with the following:
1 2 3 4 5
#!/bin/bash for i in {1001..2000} do /usr/local/mysql/bin/mysql -uroot -p123456 -P6446 -h127.0.0.1 -Dsysbench -e "insert into test1(id,report_serverid) values($i,@@server_id)" done
- Press Esc, type :wq!, and press Enter to save the file and exit.
- Execute the write request script.
1sh /home/write_6446.sh - Confirm the test data.
1/usr/local/mysql/bin/mysql -uroot -p123456 -P6446 -h127.0.0.1 -Dsysbench -e "select * from test1"

- Open the file.
- Execute the read request script.
sh /home/read_6447.sh

All read and write requests of the write port 6446 are routed to the primary node 127.0.0.1:3308, and all read requests of the read port 6447 are routed to secondary nodes 127.0.0.1:3306 and 127.0.0.1:3307, which meets the expectation.
- Start secondary databases 1 and 2.
Parent topic: Deploying MySQL Router