MySQL Forums
Forum List  »  Router & Proxy

A database redirect Question
Posted by: Pete Clapham
Date: March 26, 2008 09:31AM

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.

Options: ReplyQuote


Subject
Views
Written By
Posted
A database redirect Question
6614
March 26, 2008 09:31AM
3424
March 27, 2008 06:07AM
3658
March 28, 2008 12:44AM
3914
April 02, 2008 10:55AM
3311
April 03, 2008 06:51AM
3387
April 04, 2008 10:26AM
2700
April 07, 2008 02:45AM
3199
April 07, 2008 03:00AM
2834
December 19, 2008 02:50PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.