In MySQL Proxy scripts you can define variables and modify them.
No surprise here. If you define a variable with script wide
scope, you can use such variable and modify it between queries.
For example:
local how_many_queries = 0
function read_query(packet)
how_many_queries=how_many_queries + 1
print (how_many_queries)
end
However, when you have two clients connected to the same Proxy
instance, each one will have a separated set of local variables.
By default, MySQL Proxy protects the variables inside a session.
If two clients connect to the Proxy running the above script,
there will be a distinct count for each session, not the total of
queries, as intended.
To share information among sessions, you must use a dedicated
table inside the Proxy, called, aptly enough,
proxy.global
proxy.global.how_many_queries = proxy.global.how_many_queries or 0 …[Read more]