MySQL Proxy Cheatsheet
#
MySQL Proxy is a tool that sits between MySQL clients and MySQL servers and allows you to monitor, filter, and alter queries sent to the server.
General Commands
#
Command/Option | Example | Description |
---|
mysql-proxy --proxy-address=<address>:<port> --proxy-user=<user> --proxy-password=<password> | mysql-proxy --proxy-address=127.0.0.1:4040 --proxy-user=root --proxy-password=password | Start MySQL Proxy with specified address and credentials |
mysql-proxy --help | mysql-proxy --help | Display help information for MySQL Proxy |
Proxy Configuration
#
Command/Option | Example | Description |
---|
--proxy-upstream-server=<server> | --proxy-upstream-server=127.0.0.1:3306 | Specify the upstream MySQL server to connect to |
--proxy-downstream | --proxy-downstream | Define the downstream server configuration (if applicable) |
--proxy-read-only | --proxy-read-only | Set the proxy to read-only mode |
Scripting with Lua
#
Command/Option | Example | Description |
---|
--proxy-lua-script=<script_file> | --proxy-lua-script=myscript.lua | Load a Lua script for advanced proxying logic |
--proxy-lua-script=<script_file> | --proxy-lua-script=filter.lua | Load a Lua script to filter or modify queries |
Query Filtering
#
Command/Option | Example | Description |
---|
--proxy-filter | --proxy-filter="SELECT * FROM my_table" | Filter specific queries (basic example) |
--proxy-filter=lua:<script_file> | --proxy-filter=lua:filter_script.lua | Use a Lua script for advanced query filtering |
Status and Monitoring
#
Command/Option | Example | Description |
---|
mysql -h <proxy_address> -P <proxy_port> -u <user> -p | mysql -h 127.0.0.1 -P 4040 -u root -p | Connect to MySQL Proxy to monitor traffic |
mysql-proxy --status | mysql-proxy --status | Display the current status of MySQL Proxy |
Advanced Configuration
#
Command/Option | Example | Description |
---|
--proxy-server | --proxy-server=server1,server2 | Specify multiple upstream servers for load balancing |
--proxy-max-requests | --proxy-max-requests=10000 | Limit the number of requests per session |
This cheatsheet covers the essential MySQL Proxy commands and options, assisting you in configuring, scripting, and monitoring MySQL Proxy effectively.