Streamlining Queries to MySQL
MySQL Proxy is a tool that resides between MySQL Server and its clients, and is used to analyze and modify user queries to the server
Rahul Sah
Friday, August 29, 2008
Getting started
MySQL Proxy is available in pre-compiled binaries that can be used for installation on a supporting platform. For this article we shall be using Linux derivative Fedora 9 OS as the platform. But Proxy also needs the Lua scripting engine, and the current binary package version for MySQL Proxy contains the Lua interpreter.
 |
|
From one console, start MySQL Proxy and from the second console, connect to Proxy. When we pass queries having wrong keywords, they get replaced at the Proxy and the query with correct keywords is passed to the main server.
|
It supports MySQL 5.0.1 version and above, so it becomes a pre-requisite to have MySQL 5.0.x version of database server installed on your Fedora 9 machine. Instead of installing Proxy using a binary package, we used 'Yum' to download and install MySQL Proxy. The command for installing Proxy is as follows:
#yum install MySQL-proxy
As, Proxy also needs Lua interpreter; yum will install all dependencies that are needed for MySQL Proxy. Once the download and installation is complete, we can start using the Proxy for MySQL database server.
The syntax for MySQL Proxy is as follows:
#mysql-proxy –-proxy-lua-script=
Where is the Lua script file that is passed along to monitor and modify query transactions between the server and clients. To test the connection, start the MySQL database server and from the same console start the proxy server by passing the command 'mysql-proxy,' and again from another console connect to the proxy server using port 4040 instead of 3306 (default) as follows:
#mysql --host=127.0.0.1 --port=4040 --user=USERNAME --password
When we pass any query from this console, it connects to the proxy at port 4040 and then is redirected to the MySQL server listening at port 3306.