To start MySQL Proxy, you can run it directly from the command line:
shell> mysql-proxy
However, for most situations you will want to specify at the very least the host name or address and the port number of the backend MySQL server to which the MySQL Proxy should pass queries.
You can specify options to mysql-proxy either
on the command line, or by using a configuration file and the
--defaults-file
command-line
option to specify the file location.
If you use a configuration file, it should be formatted as follows:
Options must be specified within a
[mysql-proxy]
configuration group. For example:[mysql-proxy] admin-address =
host
:port
All configuration options should be specified in the form of a configuration name and the value you want to set.
For options that are a simple toggle on the command line (for example,
--proxy-skip-profiling
), you must usetrue
orfalse
. For example, the following is invalid:[mysql-proxy] proxy-skip-profiling
But this is valid:
[mysql-proxy] proxy-skip-profiling = true
The configuration file should have permissions of
0660
(readable and writable by user and group, no access for others).
Failure to adhere to any of these requirements causes mysql-proxy to generate an error during startup.
The following tables list the supported configuration file and command-line options.
Table 14.3. mysql-proxy Help Options
Format | Option File | Description | Introduction | Deprecated | Removed |
---|---|---|---|---|---|
--help | help | Show help options | |||
--help-admin | help-admin | Show admin module options | |||
--help-all | help-all | Show all help options | |||
--help-proxy | help-proxy | Show proxy module options |
Table 14.4. mysql-proxy Admin Options
Format | Option File | Description | Introduction | Deprecated | Removed |
---|---|---|---|---|---|
--admin-address=host:port | admin-address=host:port | The admin module listening host and port | |||
--admin-lua-script=file_name | admin-lua-script=file_name | Script to execute by the admin module | |||
--admin-password=password | admin-password=password | Authentication password for admin module | |||
--admin-username=user_name | admin-username=user_name | Authentication user name for admin module | |||
--proxy-address=host:port | proxy-address=host:port | The listening proxy server host and port |
Table 14.5. mysql-proxy Proxy Options
Format | Option File | Description | Introduction | Deprecated | Removed |
---|---|---|---|---|---|
--no-proxy | no-proxy | Do not start the proxy module | |||
--proxy-backend-addresses=host:port | proxy-backend-addresses=host:port | The MySQL server host and port | |||
--proxy-fix-bug-25371 | proxy-fix-bug-25371 | Enable the fix for Bug#25371 for older libmysql versions | 0.8.1 | ||
--proxy-lua-script=file_name | proxy-lua-script=file_name | Filename for Lua script for proxy operations | |||
--proxy-pool-no-change-user | proxy-pool-no-change-user | Do not use the protocol CHANGE_USER command to reset the connection when coming from the connection pool | |||
--proxy-read-only-backend-addresses=host:port | proxy-read-only-backend-addresses=host:port | The MySQL server host and port (read only) | |||
--proxy-skip-profiling | proxy-skip-profiling | Disable query profiling |
Table 14.6. mysql-proxy Applications Options
Format | Option File | Description | Introduction | Deprecated | Removed |
---|---|---|---|---|---|
--basedir=dir_name | basedir=dir_name | The base directory prefix for paths in the configuration | |||
--daemon | daemon | Start in daemon mode | |||
--defaults-file=file_name | The configuration file to use | ||||
--event-threads=count | event-threads=count | The number of event-handling threads | |||
--keepalive | keepalive | Try to restart the proxy if a crash occurs | |||
--log-backtrace-on-crash | log-backtrace-on-crash | Try to invoke the debugger and generate a backtrace on crash | |||
--log-file=file_name | log-file=file_name | The file where error messages are logged | |||
--log-level=level | log-level=level | The logging level | |||
--log-use-syslog | log-use-syslog | Log errors to syslog | |||
--lua-cpath=dir_name | lua-cpath=dir_name | Set the LUA_CPATH | |||
--lua-path=dir_name | lua-path=dir_name | Set the LUA_PATH | |||
--max-open-files=count | max-open-files=count | The maximum number of open files to support | |||
--pid-file=file_name | pid-file=file_name | File in which to store the process ID | |||
--plugin-dir=dir_name | plugin-dir=dir_name | Directory containing plugin files | |||
--plugins=plugin,... | plugins=plugin,... | List of plugins to load | |||
--user=user_name | user=user_name | The user to use when running mysql-proxy | |||
--version | version | Show version information |
Except as noted in the following details, all of the options can be used within the configuration file by supplying the option and the corresponding value. For example:
[mysql-proxy] log-file = /var/log/mysql-proxy.log log-level = message
--help
,-h
Command-Line Format --help
-h
Option-File Format help
Show available help options.
Command-Line Format --help-admin
Option-File Format help-admin
Show options for the admin module.
Command-Line Format --help-all
Option-File Format help-all
Show all help options.
Command-Line Format --help-proxy
Option-File Format help-proxy
Show options for the proxy module.
Command-Line Format --admin-address=host:port
Option-File Format admin-address=host:port
Permitted Values Type string
Default :4041
The host name (or IP address) and port for the administration port. The default is
localhost:4041
.Command-Line Format --admin-lua-script=file_name
Option-File Format admin-lua-script=file_name
Permitted Values Type file name
Default The script to use for the proxy administration module.
Command-Line Format --admin-password=password
Option-File Format admin-password=password
Permitted Values Type string
Default The password to use to authenticate users wanting to connect to the MySQL Proxy administration module. This module uses the MySQL protocol to request a user name and password for connections.
Command-Line Format --admin-username=user_name
Option-File Format admin-username=user_name
Permitted Values Type string
Default root
The user name to use to authenticate users wanting to connect to the MySQL Proxy administration module. This module uses the MySQL protocol to request a user name and password for connections. The default user name is
root
.Command-Line Format --basedir=dir_name
Option-File Format basedir=dir_name
Permitted Values Type directory name
The base directory to use as a prefix for all other file name configuration options. The base name should be an absolute (not relative) directory. If you specify a relative directory, mysql-proxy generates an error during startup.
Command-Line Format --daemon
Option-File Format daemon
Starts the proxy in daemon mode.
Command-Line Format --defaults-file=file_name
The file to read for configuration options. If not specified, MySQL Proxy takes options only from the command line.
Command-Line Format --event-threads=count
Option-File Format event-threads=count
Permitted Values Type numeric
Default 1
The number of event threads to reserve to handle incoming requests.
Command-Line Format --keepalive
Option-File Format keepalive
Create a process surrounding the main mysql-proxy process that attempts to restart the main mysql-proxy process in the event of a crash or other failure.
NoteThe
--keepalive
option is not available on Microsoft Windows. When running as a service, mysql-proxy automatically restarts.Command-Line Format --log-backtrace-on-crash
Option-File Format log-backtrace-on-crash
Log a backtrace to the error log and try to initialize the debugger in the event of a failure.
Command-Line Format --log-file=file_name
Option-File Format log-file=file_name
Permitted Values Type file name
The file to use to record log information. If this option is not given, mysql-proxy logs to the standard error output.
Command-Line Format --log-level=level
Option-File Format log-level=level
Permitted Values Type enumeration
Valid Values error
,warning
,info
,message
,debug
The log level to use when outputting error messages. Messages with that level (or lower) are output. For example,
message
level also outputs message withinfo
,warning
, anderror
levels.Command-Line Format --log-use-syslog
Option-File Format log-use-syslog
Log errors to the syslog (Unix/Linux only).
Command-Line Format --lua-cpath=dir_name
Option-File Format lua-cpath=dir_name
Permitted Values Type directory name
The
LUA_CPATH
to use when loading compiled modules or libraries for Lua scripts.Command-Line Format --lua-path=dir_name
Option-File Format lua-path=dir_name
Permitted Values Type directory name
The
LUA_CPATH
to use when loading modules for Lua.Command-Line Format --max-open-files=count
Option-File Format max-open-files=count
Permitted Values Type numeric
The maximum number of open files and sockets supported by the mysql-proxy process. You may need to increase this with certain scripts.
Command-Line Format --no-proxy
Option-File Format no-proxy
Disable the proxy module.
Command-Line Format --plugin-dir=dir_name
Option-File Format plugin-dir=dir_name
Permitted Values Type directory name
The directory to use when loading plugins for mysql-proxy.
Command-Line Format --plugins=plugin,...
Option-File Format plugins=plugin,...
Permitted Values Type string
A comma-separated list of plugins to load.
--proxy-address=
,host
:port
-P
host
:port
Command-Line Format --proxy-address=host:port
-P host:port
Option-File Format proxy-address=host:port
Permitted Values Type string
Default :4040
The listening host name (or IP address) and port of the proxy server. The default is
:4040
(all IPs on port 4040).--proxy-read-only-backend-addresses=
,host
:port
-r
host
:port
Command-Line Format --proxy-read-only-backend-addresses=host:port
-r host:port
Option-File Format proxy-read-only-backend-addresses=host:port
Permitted Values Type string
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.
NoteSetting this value only configures the servers within the corresponding internal structure (see
proxy.global.backends
). You can determine the backend type by checking thetype
field for each connection.You should therefore only use this option in combination with a script designed to make use of the different backend types.
When using this option on the command line, you can specify the option and the server multiple times to specify multiple backends. For example:
shell>
mysql-proxy --proxy-read-only-backend-addresses 192.168.0.1:3306 --proxy-read-only-backend-addresses 192.168.0.2:3306
When using the option within the configuration file, you should separate multiple servers with a comma. The equivalent of the preceding example would be:
... proxy-read-only-backend-addresses = 192.168.0.1:3306, 192.168.0.2:3306
--proxy-backend-addresses=
,host
:port
-b
host
:port
Command-Line Format --proxy-backend-addresses=host:port
-b host:port
Option-File Format proxy-backend-addresses=host:port
Permitted Values Type string
Default 127.0.0.1:3306
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.
When using this option on the command line, you can specify the option and the server multiple times to specify multiple backends. For example:
shell>
mysql-proxy --proxy-backend-addresses 192.168.0.1:3306 --proxy-backend-addresses 192.168.0.2:3306
When using the option within the configuration file, you should separate multiple servers with a comma. The equivalent of the preceding example would be:
... proxy-backend-addresses = 192.168.0.1:3306, 192.168.0.2:3306
Command-Line Format --proxy-pool-no-change-user
Option-File Format proxy-pool-no-change-user
Disable use of the MySQL protocol
CHANGE_USER
command when reusing a connection from the pool of connections specified by theproxy-backend-addresses
list.Command-Line Format --proxy-skip-profiling
Option-File Format proxy-skip-profiling
Disable query profiling (statistics time tracking). The default is for tracking to be enabled.
Version Removed 0.8.1 Command-Line Format --proxy-fix-bug-25371
Option-File Format proxy-fix-bug-25371
Enable a workaround for an issue when connecting to a MySQL server later than 5.1.12 when using a MySQL client library of any earlier version.
This option was removed in mysql-proxy 0.8.1. Now, mysql-proxy returns an error message at the protocol level if it sees a
COM_CHANGE_USER
being sent to a server that has a version from 5.1.14 to 5.1.17.--proxy-lua-script=
,file_name
-s
file_name
Command-Line Format --proxy-lua-script=file_name
-s file_name
Option-File Format proxy-lua-script=file_name
Permitted Values Type file name
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, the updated content is automatically used when a new connection is made.
Command-Line Format --pid-file=file_name
Option-File Format pid-file=file_name
Permitted Values Type file name
The name of the file in which to store the process ID.
Command-Line Format --user=user_name
Option-File Format user=user_name
Permitted Values Type string
Run mysql-proxy as the specified
user
.--version
,-V
Command-Line Format --version
-V
Option-File Format version
Show the version number.
The most common usage is as a simple proxy service (that is,
without additional scripting). For basic proxy operation, you must
specify at least one proxy-backend-addresses
option to specify the MySQL server to connect to by default:
shell> mysql-proxy --proxy-backend-addresses=MySQL.example.com:3306
The default proxy port is 4040
, so you can
connect to your MySQL server through the proxy by specifying the
host name and port details:
shell> mysql --host=localhost --port=4040
If your server requires authentication information, this will be passed through natively without alteration by mysql-proxy, so you must also specify the required authentication information:
shell>mysql --host=localhost --port=4040 \
--user=user_name --password=password
You can also connect to a read-only port (which filters out
UPDATE
and
INSERT
queries) by connecting to
the read-only port. By default the host name is the default, and
the port is 4042
, but you can alter the
host/port information by using the
--proxy-read-only-backend-addresses
command-line option.
For more detailed information on how to use these command-line options, and mysql-proxy in general in combination with Lua scripts, see Section 14.6.5, “Using MySQL Proxy”.