Dear all,
apologies in advance for any daft mistakes, mysql-proxy and lua are entirely new to me.
I have 3 mysql instances (that happen to be on the same host) on ports 5301,5302 and 5303.
A mysql-proxy server is running on another host.
The idea is is that a connection to test1 database is redirected to port 5301, a test2 request goes to 5302 and a test3 request goes to the 5303 instance.
mysql-proxy is fired off as:
/usr/local/sbin/mysql-proxy --proxy-backend-addresses=test1:5301 --proxy-backend-addresses=test1:5302 --proxy-backend-addresses=test1:5303 --proxy-lua-script=/usr/local/share/handshake.lua --daemon
where handshake.lua contains (and apologies again here)
function read_auth( auth )
print(" database : " .. auth.default_db)
dbtest = auth.default_db
end
function connect_server()
print("DEBUG : " .. dbtest)
if dbtest == nil then
print("Buggered if I know")
print("Using default port 5301")
proxy.connection.backend_ndx = 1
elseif dbtest == "test1" then
print("Connecting to database : " .. auth.default_db)
proxy.connection.backend_ndx = 1
print("Choosing backend port 5301");
elseif dbtest == "test2" then
print("Connecting to database : " .. auth.default_db)
proxy.connection.backend_ndx = 2
print("Choosing backend port 5302");
elseif dbtest == "test3" then
print("Connecting to database : " .. auth.default_db)
proxy.connection.backend_ndx = 3
print("Choosing backend port 5303");
end
end
Now I had expected the dbtest variable to be global, as per the lua documentation, but it appears not to be the case and the entire connect_server section fails with connections only going to the first client (unless multiple connects are made, at which point it becomes round robin).
Can anyone point me in the right direction here ? Or possibly just a better way of doing things ?
Many thanks
Pete
Edited 1 time(s). Last edit at 03/28/2008 12:40AM by Jan Kneschke.