Mysql-proxy安装使用

5167阅读 1评论2011-02-11 ubuntuer
分类:Mysql/postgreSQL

                      Mysql-proxy安装使用

一、必备软件:
1
LUA
  
可以去LUA的官方下载:

2MySQL Proxy

   这里有好多二进制版本。

 http://dev.mysql.com/downloads/mysql-proxy/#downloads

我这里下载的是suse的二进制版本

 

二、测试主机地址:
1
MySQL Proxy 安装地址:10.163.164.216 (简称A)
2
MySQL 服务器地址:10.163.164.217 (简称B)/ 10.163.164.218 (简称C)
三、安装体验
如果是按照二进制包安装的,跳过这一步。
1
LUA的安装
Tencent:#tar zxvf lua-5.1.2.tar.gz  -C /usr/local
Tencent:# cd /usr/local/
Tencent:# mv lua-5.1 lua
Tencent:# cd lua
Tencent:#make local;make install;
   
导出环境变量:

Tencent:#export LUA_CFLAGS="-I/usr/local/include" LUA_LIBS="-L/usr/local/lib -llua -ldl" LDFLAGS="-lm"
2
MySQL Proxy 安装   

Tencent:#tar -zxvf mysql-proxy-0.6.1-linux-rhel4-x86-32bit.tar.gz -C /usr/local/mysql/

Tencent:#cd /usr/local/mysql
Tencent:#mv mysql-proxy-0.6.1-linux-rhel4-x86-32bit/ mysql-proxy
Tencent:# export PATH=$PATH:/usr/local/mysql/mysql-proxy/sbin/

 

上面的两个环境变量,最好放在/etc/profile里面,这样免得终端关闭后环境变量就失效了,下次还要设置

 

3. 启动

 

Tencent:/data/wsj/mysql-proxy # cat test.lua

function read_query( packet )

    print("read_query: connection.backend_ndx: ", proxy.connection.backend_ndx)

end

Tencent:/data/wsj/mysql-proxy # mysql-proxy --proxy-address=10.163.164.216:13306 --proxy-backend-addresses=10.163.164.216:3306 --proxy-backend-addresses=10.163.164.217:3306   --proxy-lua-script=./test.lua --admin-username='test'  --admin-password='test'  --admin-lua-script=./test.lua &

 

4.启动两个终端连接mysql

Tencent:~ # mysql -usecutcs -ptcs2009@secu -h10.163.164.216 -P13306 test

使用mysql-proxy的端口

在开启mysql-proxy的地方可以看到:

read_query: connection.backend_ndx:     1

read_query: connection.backend_ndx:     1

read_query: connection.backend_ndx:     1

read_query: connection.backend_ndx:     1

read_query: connection.backend_ndx:     1

read_query: connection.backend_ndx:     1

read_query: connection.backend_ndx:     1

read_query: connection.backend_ndx:     1

read_query: connection.backend_ndx:     2

read_query: connection.backend_ndx:     2

read_query: connection.backend_ndx:     2

 

简易的实现了mysql的轮询

上一篇:查看 MySQL 数据库中 表大小
下一篇:MySQL Query Profile

文章评论