Record the process of setting up MySQL Proxy:
Configuration:
A total of three Ubuntu servers are:
MySQL Proxy: 192.168.1.101 (untua)
MySQL 1: 192.168.1.104 (ubuntub)
MySQL 2: 192.168.1.103 (ubuntuc)
Install MySQL proxy on Ubuntu-:
Reference official documents: http://dev.mysql.com/doc/refman/5.1/en/mysql-proxy-install-binary.html
Install Lua
Ununtua @ ununtua :~ $ Sudo apt-Get install lua5.1
Install MySQL proxy
Ununtua @ ununtua:/usr/local $ sudo tar zxf mysql-proxy-0.8.1-linux-glibc2.3-x86-32bit.tar.gz
Ununtua @ ununtua:/usr/local/mysql-proxy-0.8.1-linux-glibc2.3-x86-32bit $ Path = $ path:/usr/local/mysql-proxy-0.8.1-linux-glibc2.3-x86-32bit/bin/
On Ubuntu-B and Ubuntu-C
Install MySQL to allow remote access.
Create Database 'rep 'separately'
Create tables separately:
Mysql> DESC user;
+ ------- + ------------- + ------ + ----- + --------- + ---------------- +
| FIELD | type | null | key | default | extra |
+ ------- + ------------- + ------ + ----- + --------- + ---------------- +
| ID | int (11) | no | pri | null | auto_increment |
| Name | varchar (30) | Yes | null |
+ ------- + ------------- + ------ + ----- + --------- + ---------------- +
In ubuntu-B:
Mysql> insert into user (name) values ('B ');
In ubuntu-C:
Mysql> insert into user (name) values ('C ');
Go back to Ubuntu-A and start mysql-Proxy:
Ununtua @ ununtua :~ $ Mysql-proxy -- proxy-read-only-backend-addresses = 192.168.1.104: 3306 -- proxy-backend-addresses = 192.168.1.102: 3306 -- admin-LUA-script =/usr/local/mysql-proxy-0.8.1-linux-glibc2.3-x86-32bit/share/doc/MySQL-proxy/rw-splitting.lua -- admin-username = root -- admin-Password =''
Connect to MySQL proxy on another computer:
The operation method is the same as that of a common database, but the port number is different.
Localhost :~ ADMIN $ mysql-uroot-p-h 192.168.1.101-P 4040
Mysql> Use rep;
Database changed
Mysql> select * from user;
Open several more connections and perform more addition and query operations to check whether the operations are allocated to different databases. Some articles say that load balancing can be implemented only when there are enough connections. I don't know what the rules are. During my local operations, the database operation results were actually done through proxy-backend-addresses. Is -- proxy-read-only-backend-addresses ignored? Why? Further research is required.
References:
Http://blog.csdn.net/yueliangdao0608/article/details/2398655
Http://forums.mysql.com/read.php? 146,192274, 192274 # msg-192274
Http://jan.kneschke.de/2007/8/1/mysql-proxy-learns-r-w-splitting/