0

I am trying to use MySQL-Proxy to achieve the following use case.

  1. Client connects to MySQL proxy server port, fires query A.
  2. MySQL Proxy port listens to this, replaces query A with B and returns result of B to client.

As I see from the doc, I have started two instances as follows,

Start a proxy server that proxies 3306; From the doc, I see it default runs on 4040

.\mysql-proxy.exe --proxy-backend-addresses=127.0.0.1:3306 --proxy-lua-script=admin.lua

Connect to MySQL proxy 4040

 ./mysql --host=localhost --port=4040 -u root -p

First few lines in admin.lua

function read_query(packet)
     if packet:byte() == proxy.COM_QUERY then
        print("we got1 a normal query: " .. packet:sub(2))
      end
    if packet:byte() ~= proxy.COM_QUERY then
        set_error("[admin] we only handle text-based queries (COM_QUERY)")
        return proxy.PROXY_SEND_RESULT
    end

I am getting a MySQL shell, but I am not able to execute any query and get results. packet:sub(2) seems to return empty string irrespective of whatever query I write like select * from db.table in the original DB running at 3306 and I am not able to see any results and I am getting only ERROR 1105 (07000): use 'SELECT * FROM help' to see the supported commands and I can't even execute that query.

Please let me know how can I rewrite query A to B here by this or any other easier way to proxy. It's needed one time in my local machine.

Mail
  • 314
  • 1
  • 2
  • 9

0 Answers0