Official website: http://dev.mysql.com/downloads/mysql-proxy
Learning version: mysql-proxy-0.8.5-1.el6.x86_64
Environment Preparation:
mysql_a
(10.0.13-mariadb) Read and write :n1.test.com;172.16.2.11 Mysql_b (
10.0.13-mariadb) Read only: n2.test.com;172.16.2.12
Mysql-proxy (
0.8.5):n3.test.com;172.16.2.13 Mysql-proxy:epel Source: yum-y Install mysql-proxy read/write separation using the Rw-splitting.lua script in the official binary format file # Mysql-proxy--help-all==> Command HelpConfiguration file:/etc/mysql-proxy.cnf
[Mysql-proxy]daemon = Truepid-file =/var/run/mysql-proxy.pidlog-file =/var/log/mysql-proxy.loglog-level = Debug #调试级别max-open-files = 1024plugins = Admin,proxyuser = mysql-proxy# #Proxy configurationproxy-address = 0.0.0.0:3306 #代理服务监听的地址和端口proxy-backend-addresses = 172.16.2.11:3306 #支持读写操作的后端mysql proxy-read-only-backend-addresses = 172.16.2.12:3306 # read-only backend #proxy-lua-script = Proxy-lua-script =/usr/lib64/ Mysql-proxy/lua/rw-splitting.lua #读写分离脚本 #proxy-skip-profiling = true## Admin configurationadmin-address = 0.0.0.0:4041 #msyql-prxoy-connected management Port Admin-lua-script =/usr/lib64/mysql-proxy/lua/admin.lua # Msyql-prxoy Admin Script Location admin-username = admin #msyql-prxoy Admin Account admin-password = admin #msyql-prxoy admin password to be connected
mysql-proxy.cnf
Back-end hosts need to create an authorized account
- mysql> GRANT All on * * to [e-mail protected] ' 172.16.%.% ' identified by ' cm ';
- mysql> FLUSH privileges;
initiate a query or modify a statement in Mysql-proxy
- # mysql-uroot-h172.16.2.13-pcm-e ' SHOW DATABASES; '
- # mysql-uroot-h172.16.2.13-pcm-e ' CREATE DATABASE test9; '
- MySQL on the back end can see the created database Test9
Native Login Mysql-proxy Management
- # mysql-uadmin-padmin-p4041-h172.16.2.13
Get help after mysql-proxy after landing on the machine
- Mysql> SELECT * from Help
After the native login mysql-proxy after the query backend node
- mysql> SELECT * from backends;
MySQL read and write separation of Mysql-proxy