Not long ago, I conducted an experiment on MySQL read/write splitting. I also referred to a lot of materials. thank you for providing the materials.
Environment: 192.168.100.210
192.168.100.104
192.168.100.208
192.168.100.106
Note: 210,104 is used as a MySQL database.
208 as MySQL-proxy.
106 as the testing machine.
Download related software:
Lua
Www.lua.org
Mysql-proxy
Http://mysql.cdpa.nsysu.edu.tw/Downloads/MySQL-Proxy/
1. Install Lua on 208
# Tar zxvf lua-5.1.4.tar.gz-C/usr/local
# Cd/usr/local
# Mv lua-5.1.4 Lua
# Cd Lua
# Make // make: the system list is displayed.
Command to use
# Make Linux // here is Linux
# Make install
2. Install mysql-proxy
# Tar-zxvf mysql-proxy-0.6.0-linux-rhas4-x86.tar.gz-C/usr/local/
# Cd/usr/local/
# Mv mysql-proxy-0.6.0-linux-rhas4-x86 mysql-proxy
# Export Path = $ path:/usr/local/MySQL-proxy/sbin/
# Mysql-proxy -- proxy-read-only-backendaddresses = 192.168.100.210: 3306
-- Proxy-backend-addresses = 192.168.100.104: 3306
-- Proxy-LUA-script =/home2/mysql-proxy-0.6.0-linux-rhas4-x86/share/MySQL-proxy/rw-splitting.lua &
3. Set permissions on 210,104
Mysql> grant all privileges on backup. *
[Email = backup @ '%'] backup @ '%' [/Email]
Identified by 'shenyun ';
// Here, a backup account and password shenxun are provided. The database for read and write operations is backup.
4. perform the test.
Connect mysql-proxy 106 with MySQL 208:
/Usr/bin/MySQL-u backup-pshenxun-p4040-H 192.168.100.208-D backup
Create a table
Create Table Haha (ID int, name char (6 ));
Then we went to 210 and 104 to check the database. We can see that 210 is not the same
The database table to be written, while 104 has the data table just written.
Now let's modify the above command
Mysql-proxy -- proxy-backend-addresses = 192.168.100.210: 3306 -- proxy-backend-addresses = 192.168.100.104: 3306 -- proxy-LUA-script =/home2/mysql-proxy-0.6.0-linux-rhas4-x86/share/MySQL-proxy/rw-splitting.lua &
Then we create another table on 208.
Create Table Xixi (ID int, name char (6 ));
At this time, I went to 210 and 104 to check the database and found that both databases had the data just written.
Database table.
This fully demonstrates that our database read/write splitting has been implemented.