Verifying Read/Write Splitting and Load Balancing
- Create a test database and a test table.
- Connect to the MySQL database.
1/usr/local/mysql/bin/mysql -uroot -p123456 -S /data/mysql/run/mysqlm.sock
- Create a test database and a test table.
1 2 3 4 5 6 7
create database sysbench; use sysbench; CREATE TABLE `test1` ( `id` bigint(20) NOT NULL, `report_serverid` varchar(100) DEFAULT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1;
- Confirm that data is synchronized to secondary database 1.
1 2 3 4
/usr/local/mysql/bin/mysql -uroot -p123456 -S /data/mysql/run/mysqls.sock show databases; use sysbench; show tables;
- Confirm that data is synchronized to secondary database 2.
1 2 3 4
/usr/local/mysql/bin/mysql -uroot -p123456 -S /data/mysql/run/mysqls2.sock show databases; use sysbench; show tables;
- Connect to the MySQL database.
- Start MySQL Router.
1mysqlrouter &
- Verify that the MySQL Router ports are started properly.
1 2
netstat -an|grep 6446 netstat -an|grep 6447

If the command output is the same as that shown in the figure, the ports are started.
- Perform a query test.
- Open the file.
vim /home/read_6446.sh
- Add the following content to the file:
1 2 3 4 5
#!/bin/bash for i in {1..1000} do /usr/local/mysql/bin/mysql -uroot -p123456 -P6446 -h127.0.0.1 -e "select @@server_id" done
- Press Esc, type :wq!, and press Enter to save the file and exit.
- Execute the read request script.
1sh /home/read_6446.sh
All read requests of the write port (port 6446) are sent to the primary node as expected.
- Open the file.
vim /home/read_6447.sh
- Add the following content to the file:
1 2 3 4 5
#!/bin/bash for i in {1..1000} do /usr/local/mysql/bin/mysql -uroot -p123456 -P6447 -h127.0.0.1 -e "select @@server_id" done
- Press Esc, type :wq!, and press Enter to save the file and exit.
- Execute the read request script.
1sh /home/read_6447.sh
Read requests sent to the read port 6447 are routed to the two secondary nodes in polling mode as expected.
- Open the file.
- Perform a write test.
- Open the file.
vim /home/write_6446.sh
- Add the following content to the file:
1 2 3 4 5
#!/bin/bash for i in {1..1000} 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"

All write requests of the write port (port 6446) are sent to the primary node as expected.
- Perform a write test through port 6447.
/usr/local/mysql/bin/mysql -uroot -p123456 -P6447 -h127.0.0.1 -Dsysbench -e "insert into test1(id,report_serverid) values(1001,@@server_id)"

- Open the file.
Parent topic: Deploying MySQL Router