mysql proxy配置参数_亲亲宝宝 » MySQL Proxy在window下的配置及使用

1,原本为Cilent-Server直连这种拓扑,现在引入MySQL Proxy,变成Client-Proxy-Server。

2,原本为了实现高容载能力,对于Server采取了多台并存,Master/Slave甚至是Master/Master等方式的复制集群,配置管理都比较复杂。而引入了Proxy以后,中间存在了这样一个Store-Forward的proxy环节,对于程序开发完全透明。

3,在这个环节,我们可以通过一种脚本语言来控制这个proxy的行为,例如对于Client进来的查询依照某种条件过滤,甚至依照某种条件改写,再导向后端的Server。

4,凭借自己实现的filtering或rewriting,我们可以实现很多目的,例如Failover,例如Load balance。或者更无聊些我们可以对Client进来的带有弱智语法错误的SQL语句进行修正。

mysql-proxy可以做读写分离、负载均衡、故障转移。

1、下载windows的包,解压后,直接运行就可以,并且也支持lua脚本,太方便了;

2、命令行运行的参数:

–help-all — show all help options.

–help-admin — show options for the admin-module.

–help-proxy — Show options for the proxy-module.

–admin-address=host:port — specify the host name (or IP address) and port for the administration port.

The default is localhost:4041.

–proxy-address=host:port — the listening host name (or IP address) and port of the proxy server.

The default is localhost:4040.

–proxy-read-only-backend-address=host:port — the listening host name (or IP address) and

port of the proxy server for read-only connections. The default is for this information not to be set.

–proxy-backend-addresses=host:port — the host name (or IP address) and port of the MySQL server to connect to.

You can specify multiple backend servers by supplying multiple options.

Clients are connected to each backend server in round-robin fashion.

For example, if you specify two servers A and B, the first client connection will go to server A;

the second client connection to server B and the third client connection to server A.

–proxy-skip-profiling — disables profiling of queries (tracking time statistics). The default is for tracking to be enabled.

–proxy-fix-bug-25371 — gets round an issue when connecting to a MySQL server later than 5.1.12

when using a MySQL client library of any earlier version.

–proxy-lua-script=file — specify the Lua script file to be loaded.

Note that the script file is not physically loaded and parsed until a connection is made.

Also note that the specified Lua script is reloaded for each connection;

if the content of the Lua script changes while mysql-proxy is running then the updated content will automatically

be used when a new connection is made.

–daemon — starts the proxy in daemon mode.

–pid-file=file — sets the name of the file to be used to store the process ID.

–version — show the version number.

3、典型配置案例:

1、最基础的应用,代理单个数据库服务器,这样就可以通过4040端口访问mysql数据库。

mysql-proxy –proxy-backend-addresses=192.168.18.110:3306

2、连接多个数据库服务器,假如A and B. 第一个客户端连接到 A,第二个连接到 B。

如果有一台停止服务时,代理会自动检测到,有新连接时会自动连接到一台正常的数据库。

mysql-proxy \

–proxy-backend-addresses=narcissus:3306 \

–proxy-backend-addresses=nostromo:3306

3、数据库读写分离,192.168.18.110负责写入,192.168.18.107负责读取数据,当然也可以再增加读取数据的服务器。

mysql-proxy \

–proxy-backend-addresses=192.168.18.110:3306 \

–proxy-read-only-backend-addresses=192.168.18.107:3306

这种方式常被理解为可以读写分离了,但是实际不是的。mysql-proxy不能区分哪些是发往从服务器的,还需要自己用脚本控制,见第四种方式。

4、 Lua 脚本能很好的控制连接和分布, 以及查询及返回的结果集.

使用Lua脚本时,必须使用 –proxy-lua-script 指定脚本的名称。

直到产生连接的时候才会读取脚本,也就是修改脚本后不用重新启动服务。

mysql-proxy –proxy-lua-script=rw-splitting.lua –proxy-backend-addresses=192.168.18.110:3306 –proxy-read-only-backend-addresses=192.168.18.107:3306

注意的问题:

1、proxy的读写分离机制是先把最初的几条查询发到master上建立连接,

当发送到master上的查询数超过连接池的最小值时开始把查询

2、LAST_INSERT_ID不能发送到主服务器上, 226 行修改为下面的就可以了

elseif not is_insert_id and token.token_name == “TK_FUNCTION” then

3、使用默认的rw-splitting.lua时,会提示找不到proxy-command,我把mysql-proxy的路径设置为系统路径,然后在share目录下运行就一切Ok了,在运行中输入cmd,然后cd C:\tools\mysql-proxy\share。

4、字符乱码

通过proxy连上数据库之后,查到的字符串始终是乱码,即便手工执行了set names ‘utf8’也没有效果。

解决办法,mysql server必须设置

1.[mysqld]

2.skip-character-set-client-handshake

3. init-connect=’SET NAMES utf8’

4. default-character-set=utf8

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值