The following example injects additional
a different ID to the ID of the original query. Within read_query_result(), if the ID for the injected
queries is identified, we display the result row, and return the
the function so that the result is not returned to the client. If the result is from any other query, we print
out the query time information for the query and return the default, which passes on the result set
unchanged. We could also have explicitly returned
client.
function read_query( packet )
if packet:byte() == proxy.COM_QUERY then
end
end
function read_query_result(inj)
if inj.id == 2 then
else
end
end
For further examples, see
15.7.5. Using MySQL Proxy
There are a number of different ways to use MySQL Proxy. At the most basic level, you can allow
MySQL Proxy to pass queries from clients to a single server. To use MySQL Proxy in this mode, you
just have to specify on the command line the backend server to which the proxy should connect:
shell>
mysql-proxy --proxy-backend-addresses=sakila:3306
If you specify multiple backend MySQL servers, the proxy connects each client to each server in a
round-robin fashion. Suppose that you have two MySQL servers, A and B. The first client to connect is
connected to server A, the second to server B, the third to server A. For example:
shell>
mysql-proxy \
--proxy-backend-addresses=narcissus:3306 \
--proxy-backend-addresses=nostromo:3306
When you specify multiple servers in this way, the proxy automatically identifies when a MySQL server
has become unavailable and marks it accordingly. New connections are automatically attached to a
server that is available, and a warning is reported to the standard output from mysql-proxy:
network-mysqld.c.367: connect(nostromo:3306) failed: Connection refused
network-mysqld-proxy.c.2405: connecting to backend (nostromo:3306) failed, marking it as down for ...
Lua scripts enable a finer level of control, both over the connections and their distribution and how
queries and result sets are processed. When using an Lua script, you must specify the name of the
script on the command line using the
shell>
mysql-proxy --proxy-lua-script=mc.lua --proxy-backend-addresses=sakila:3306
When you specify a script, the script is not executed until a connection is made. This means that faults
with the script are not raised until the script is executed. Script faults will not affect the distribution of
queries to backend MySQL servers.
Using MySQL Proxy
SELECT NOW()
proxy.queries:append(2, string.char(proxy.COM_QUERY) .. "SELECT NOW()", {resultset_is_neede
proxy.queries:append(1, packet, {resultset_is_needed = true})
proxy.queries:append(2, string.char(proxy.COM_QUERY) .. "SELECT NOW()", {resultset_is_neede
return proxy.PROXY_SEND_QUERY
for row in inj.resultset.rows do
print("injected query returned: " .. row[1])
end
return proxy.PROXY_IGNORE_RESULT
print("query-time: " .. (inj.query_time / 1000) .. "ms")
print("response-time: " .. (inj.response_time / 1000) .. "ms")
Section 15.7.5, "Using MySQL
--proxy-lua-script
statements into the query queue, giving them
proxy.PROXY_IGNORE_RESULT
proxy.PROXY_IGNORE_RESULT
Proxy".
[1404]
1420
to the MySQL
option:
from
Need help?
Do you have a question about the 5.0 and is the answer not in the manual?
Questions and answers