收到Mysql AB的邮件, 看到 Mysql Proxy 这个东西发布的时候,我很兴奋.
因为当时我在弄一个项目,需要网通和电信两个镜像站点同时读写一个布署在电信服务器上的mysql数据库.中间有台双线的服务器可以做数据中转,试过很多方案都不理想.
Mysql Proxy很好的解决了我的问题.虽然目前还是测试版,可到现在三个月了,我的这个业务一直很稳定的在运行着.
下面就介绍一下当时的情况:
目的很明确,在下面的图片中,我仅希望web server 3(网通线路)的服务器能快速读写Data base server中的数据.
<IMG height=238 alt="" src="http://img.bitscn.com/upimg/allimg/c140719/1405M3360DK0-10JC.jpg" width=478 border=0>
$ tar zxf<EM class=replaceable><CODE>mysql-proxy-0.5.0.tar.gz</CODE></EM><BR>$ cp ./mysql-proxy-0.5.0/sbin/mysql-proxy /usr/local/sbin<BR><BR>命令语法很简单,它默认使用4040端口.<BR>假设你想代理本机的mysql,直接执行<BR>$ mysql-proxy &<BR>就可以了.注意,mysql server必须是5.0或者更高版本.<BR><BR>然后测试一下<BR>$ mysql --host=127.0.0.1 --port=4040 --user=root --password<BR>输入你的root密码,嘿嘿.和使用3306端口的一样.<BR><BR>有人会问:神经病吗?我直接用3306更直接和快速呀,为何多此一举,加个代理?<BR>我能想到的是:<BR>1.在大的应用时,有时需要将读写分离,提高效率,就会需要.<BR>2.数据库做负载平衡(load balancing)时,也需要.<BR>3.对local用户不需要复杂的安全验证,对远程用户需要ssl时.<BR>4.其它一些特殊要求.<BR>
$ mysql-proxy --proxy-backend-addresses=192.168.0.1:3306 &<BR><BR>测试连接:<BR>$ mysql --host=localhost --port=4040 --user=root --password<BR>输入Data base server的密码.连接上了.<BR><BR>到网通服务器上测试,<BR>$ mysql --host=双线服务器的网通IP地址 --port=4040 --user=root --password<BR>输入密码后,立即就能看到mysql>了.<BR><BR>套上<U><STRONG>PHP</STRONG></U><U><STRONG>代码</STRONG></U>,测试. 速度非常好.目的达到了. <BR><BR>如果你也有类似或者 mysql server 负载平衡、容错 等的应用需求时,不妨也试试mysql-proxy,<BR>相信不会让你失望的.<BR>也欢迎和我探讨这方面的问题. 我的联系方式在这里!!<BR>-------------------------------------------------------------------<BR>附mysql-proxy 的所有语法命令:<BR>$ mysql-proxy --help-all<BR><BR>Usage:<BR><BR>mysql-proxy [OPTION...] - MySQL Proxy<BR><BR>Help Options:<BR><BR>-?, --help Show help options<BR>--help-all Show all help options<BR>--help-admin Show options for the admin-module<BR>--help-proxy Show options for the proxy-module<BR><BR>admin module<BR><BR>--admin-address=<host:port>listening address:port of internal admin-server (default: :4041)<BR><BR><BR><BR>proxy-module<BR><BR>--proxy-address=<host:port>listening address:port of the proxy-server (default: :4040)<BR>--proxy-read-only-backend-addresses=<host:port>address:port of the remote slave-server (default: not set)<BR>--proxy-backend-addresses=<host:port>address:port of the remote backend-servers (default: 127.0.0.1:3306)<BR>--proxy-skip-profiling disables profiling of queries (default: enabled)<BR>--proxy-fix-bug-25371 fix bug #25371 (mysqld >5.1.12) for older libmysql versions<BR>--proxy-lua-script=<file>filename of the lua script (default: not set)<BR>--no-proxy Don't start proxy-server<BR><BR><BR><BR>Application Options:<BR>-V, --version Show version<BR>--daemon Start in daemon-mode<BR>--pid-file=<file>PID file in case we are started as daemon<BR>