MySQL Proxy Scripting
1408
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
read_query()
function, this function is not triggered. You can use this to edit 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
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.
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.
Summary of Contents for 5.0
Page 1: ...MySQL 5 0 Reference Manual ...
Page 18: ...xviii ...
Page 60: ...40 ...
Page 396: ...376 ...
Page 578: ...558 ...
Page 636: ...616 ...
Page 844: ...824 ...
Page 1234: ...1214 ...
Page 1427: ...MySQL Proxy Scripting 1407 ...
Page 1734: ...1714 ...
Page 1752: ...1732 ...
Page 1783: ...Configuring Connector ODBC 1763 ...
Page 1793: ...Connector ODBC Examples 1773 ...
Page 1839: ...Connector Net Installation 1819 2 You must choose the type of installation to perform ...
Page 2850: ...2830 ...
Page 2854: ...2834 ...
Page 2928: ...2908 ...
Page 3000: ...2980 ...
Page 3122: ...3102 ...
Page 3126: ...3106 ...
Page 3174: ...3154 ...
Page 3232: ...3212 ...