Oracle 5.0 Reference Manual page 1428

Table of Contents

Advertisement

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:
• connect_server(): This function is called each time a connection is made to MySQL Proxy from a
client. You can use this function during load-balancing to intercept the original connection and decide
which server the client should ultimately be attached to. If you do not define a special solution, a
simple round-robin style distribution is used by default.
• read_handshake(): This function is called when the initial handshake information is returned
by the server. You can capture the handshake information returned and provide additional checks
before the authorization exchange takes place.
• read_auth(): This function is called when the authorization packet (user name, password, default
database) are submitted by the client to the server for authentication.
• read_auth_result(): This function is called when the server returns an authorization packet to
the client indicating whether the authorization succeeded.
• read_query(): This function is called each time a query is sent by the client to the server. You
can use this to edit and manipulate the original query, including adding new queries before and
after the original statement. You can also use this function to return information directly to the client,
bypassing the server, which can be useful to filter unwanted queries or queries that exceed known
limits.
• read_query_result(): This function is called each time a result is returned from the server,
providing you have manually injected queries into the query queue. If you have not explicitly injected
queries within the
result set, or to remove or filter the result sets generated from additional queries you injected into the
queue when using read_query().
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
connect_server()
read_handshake()
read_auth()
read_auth_result()
read_query()
read_query_result()
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
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.
15.7.4.1. Proxy Scripting Sequence During Query Injection
The following figure gives an example of how the proxy might be used when injecting queries into the
query queue. Because the proxy sits between the client and MySQL server, what the proxy sends
to the server, and the information that the proxy ultimately returns to the client, need not match or
correlate. Once the client has connected to the proxy, the sequence shown in the following diagram
occurs for each individual query sent by the client.
MySQL Proxy Scripting
function, this function is not triggered. You can use this to edit the
read_query()
Supplied Information
None
None
None
None
Query
Query result
Direction
Client to Server
Server to Client
Client to Server
Server to Client
Client to Server
Server to Client
1408
and to return
read_query()

Advertisement

Table of Contents
loading

This manual is also suitable for:

Mysql 5.0

Table of Contents