16.7.3 MySQL Proxy Command Options

To start MySQL Proxy, you can run it directly from the command line:

shell> mysql-proxy

For most situations, you specify at 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, format it as follows:

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 16.4 mysql-proxy Help Options

--helpShow help options
--help-adminShow admin module options
--help-allShow all help options
--help-proxyShow proxy module options

Table 16.5 mysql-proxy Admin Options

--admin-address=host:portThe admin module listening host and port
--admin-lua-script=file_nameScript to execute by the admin module
--admin-password=passwordAuthentication password for admin module
--admin-username=user_nameAuthentication user name for admin module
--proxy-address=host:portThe listening proxy server host and port

Table 16.6 mysql-proxy Proxy Options

--no-proxyDo not start the proxy module 
--proxy-backend-addresses=host:portThe MySQL server host and port 
--proxy-fix-bug-25371Enable the fix for Bug #25371 for older libmysql versions0.8.1
--proxy-lua-script=file_nameFilename for Lua script for proxy operations 
--proxy-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:portThe MySQL server host and port (read only) 
--proxy-skip-profilingDisable query profiling 

Table 16.7 mysql-proxy Applications Options

--basedir=dir_nameThe base directory prefix for paths in the configuration
--daemonStart in daemon mode
--defaults-file=file_nameRead only named option file
--event-threads=countNumber of event-handling threads
--keepaliveTry to restart the proxy if a crash occurs
--log-backtrace-on-crashTry to invoke the debugger and generate a backtrace on crash
--log-file=file_nameThe file where error messages are logged
--log-level=levelThe logging level
--log-use-syslogLog errors to syslog
--lua-cpath=dir_nameSet the LUA_CPATH
--lua-path=dir_nameSet the LUA_PATH
--max-open-files=countThe maximum number of open files to support
--pid-file=file_nameFile in which to store process ID
--plugin-dir=dir_nameDirectory containing plugin files
--plugins=plugin,...List of plugins to load
--user=user_nameThe user to use when running mysql-proxy
--versionShow 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:

log-file = /var/log/mysql-proxy.log
log-level = message

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 16.7.5, “Using MySQL Proxy”.