Spec-Zone .ru
спецификации, руководства, описания, API

15.7.4. MySQL Proxy Scripting

15.7.4.1. Proxy Scripting Sequence During Query Injection
15.7.4.2. Internal Structures
15.7.4.3. Capturing a Connection with connect_server()
15.7.4.4. Examining the Handshake with read_handshake()
15.7.4.5. Examining the Authentication Credentials with read_auth()
15.7.4.6. Accessing Authentication Information withread_auth_result()
15.7.4.7. Manipulating Queries with read_query()
15.7.4.8. Manipulating Results with read_query_result()

You can control how MySQL Proxy manipulates and works with the queries and results that are passed on to the MySQL server through the use of the embedded Lua scripting language. You can find out more about the Lua programming language from the Lua Web site.

The following diagram shows an overview of the classes exposed by MySQL Proxy.

MySQL Proxy architecture

The primary interaction between MySQL Proxy and the server is provided by defining one or more functions through an Lua script. A number of functions are supported, according to different events and operations in the communication sequence between a client and one or more backend MySQL servers:

The following table lists MySQL proxy and server communication functions, the supplied information, and the direction of information flow when the function is triggered.

Function Supplied Information Direction
connect_server() None Client to Server
read_handshake() None Server to Client
read_auth() None Client to Server
read_auth_result() None Server to Client
read_query() Query Client to Server
read_query_result() Query result Server to Client

By default, all functions return a result that indicates whether the data should be passed on to the client or server (depending on the direction of the information being transferred). This return value can be overridden by explicitly returning a constant indicating that a particular response should be sent. For example, it is possible to construct result set information by hand within read_query() and to return the result set directly to the client without ever sending the original query to the server.

In addition to these functions, a number of built-in structures provide control over how MySQL Proxy forwards queries and returns the results by providing a simplified interface to elements such as the list of queries and the groups of result sets that are returned.