【原创】MySQL Proxy - 命令行选项

本文介绍MySQLProxy的基本启动方法及配置选项,包括命令行启动、配置文件使用、常见配置项等,帮助读者快速掌握MySQLProxy的部署与使用。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

       直接从命令行上启动 MySQL Proxy :  

?
1
shell> mysql-proxy

       在大多数情况下,你至少应该确定 MySQL Proxy 应该将 query 转发到哪个 backend MySQL server ,即需要指定其 host 名或地址,以及端口号信息。 

       可以在命令行中直接指定选项,也可以在配置文件中指定,同时使用 --defaults-file 命令行参数指定配置文件的位置。 

       如果你采用了配置文件的方式,其格式需要按照如下配置: 

1.在 [mysql-proxy] 配置组中指定选项,例如: 

?
1
2
[mysql-proxy]
admin-address = host:port

2.以配置名和配置值对的形式指定全部配置选项。 

3.对于简单开关形式的命令行选项(例如 --proxy-skip-profiling),使用 true 或者 false 。例如,下面的形式是不合法的: 

?
1
2
[mysql-proxy]
proxy-skip-profiling

但下面是合法的 

?
1
2
[mysql-proxy]
proxy-skip-profiling = true

4.设置配置文件的 Unix 权限为 0660(对于用户和组可读、可写,对于其他人不可访问) 

上述条件任意一个不满足都会导致 mysql-proxy 在启动时产生错误。 


下面的表格中列出了支持的选项配置。  



Table 15.4. mysql-proxy Help Options

FormatOption FileDescription
--help Show help options
--help-admin Show admin module options
--help-all Show all help options
--help-proxy Show proxy module options


Table 15.5. mysql-proxy Admin Options

FormatOption FileDescription
--admin-address=host:portadmin-address=host:portThe admin module listening host and port
--admin-lua-script=file_nameadmin-lua-script=file_nameScript to execute by the admin module
--admin-password=passwordadmin-password=passwordAuthentication password for admin module
--admin-username=user_nameadmin-username=user_nameAuthentication user name for admin module
--proxy-address=host:portproxy-address=host:portThe listening proxy server host and port


Table 15.6. mysql-proxy Proxy Options

FormatOption FileDescriptionRemoved
--no-proxyno-proxyDo not start the proxy module 
--proxy-backend-addresses=host:portproxy-backend-addresses=host:portThe MySQL server host and port 
--proxy-fix-bug-25371proxy-fix-bug-25371Enable the fix for Bug #25371 for older libmysql versions0.8.1
--proxy-lua-script=file_nameproxy-lua-script=file_nameFilename for Lua script for proxy operations 
--proxy-pool-no-change-userproxy-pool-no-change-userDo not use the protocol CHANGE_USER command to reset the connection when coming from the connection pool 
--proxy-read-only-backend-addresses=host:portproxy-read-only-backend-addresses=host:portThe MySQL server host and port (read only) 
--proxy-skip-profilingproxy-skip-profilingDisable query profiling 


Table 15.7. mysql-proxy Applications Options

FormatOption FileDescription
--basedir=dir_namebasedir=dir_nameThe base directory prefix for paths in the configuration
--daemondaemonStart in daemon mode
--defaults-file=file_name The configuration file to use
--event-threads=countevent-threads=countThe number of event-handling threads
--keepalivekeepaliveTry to restart the proxy if a crash occurs
--log-backtrace-on-crashlog-backtrace-on-crashTry to invoke the debugger and generate a backtrace on crash
--log-file=file_namelog-file=file_nameThe file where error messages are logged
--log-level=levellog-level=levelThe logging level
--log-use-sysloglog-use-syslogLog errors to syslog
--lua-cpath=dir_namelua-cpath=dir_nameSet the LUA_CPATH
--lua-path=dir_namelua-path=dir_nameSet the LUA_PATH
--max-open-files=countmax-open-files=countThe maximum number of open files to support
--pid-file=file_namepid-file=file_nameFile in which to store the process ID
--plugin-dir=dir_nameplugin-dir=dir_nameDirectory containing plugin files
--plugins=plugin,...plugins=plugin,...List of plugins to load
--user=user_nameuser=user_nameThe user to use when running mysql-proxy
--version Show version information

(略) 

       最通常的用法为作为一个简单的 proxy 服务使用(即不使用任何附件的脚本)。在基本 proxy 运行中,你必须通过 proxy-backend-addresses 选项指定至少一个默认要连接的 MySQL 服务器: 

?
1
shell> mysql-proxy --proxy-backend-addresses=MySQL.example.com:3306

       默认 proxy 端口为 4040 ,故你可以通过指定主机名和端口号来使用 proxy 连接到 MySQL 服务器。 

?
1
shell> mysql --host=localhost --port=4040


       如果你的服务器要求提供鉴权信息 - 这些鉴权信息均会被 mysql-proxy 不作任何改变的透传 - 故你必须指定所需的鉴权信息: 

?
1
2
shell> mysql --host=localhost --port=4040 \
    --user=user_name --password=password

       你同样可以连接到一个只读端口上(在该端口上会对 UPDATE 和 INSERT 类型的 query 进行过滤)。默认情况下,只读服务的主机名为默认,端口为 4042 ,但是你可以通过 --proxy-read-only-backend-addresses 命令行选项来改变其相应主机名和端口值。 

       更多使用命令行选项,以及如何组合使用 mysql-proxy 与 Lua 脚本的详细信息,请参阅 15.7.5, “Using MySQL Proxy” 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值