MySQL proxy errors

Hi,

I’m getting the following error when connecting to a remote MySQL server through HAProxy:

Lost connection to MySQL server at 'reading initial communication packet', system error: 0 [Code: 2013]

My config:

listen MySQL
        bind localhost:3306
        mode tcp
        maxconn 10
        balance roundrobin
        server mysql_slave remotemysql.com:3306 maxconn 1

(I use the 127.0.0.1:3306 address to connect from few client applications, on the same machine where HAProxy is installed). OS is Ubuntu 20.04.

Here are my requirements:

  1. Multiple applications connect to the router/proxy against the same MySQL credentials (same DB and user)
  2. Router/proxy establishes a single connection using the same MySQL credentials than the client applications; that is, doesn’t simply forward each connection coming from each application to the server.
  3. Queries from all clients will end in the single MySQL connection from the proxy to the remote server, and get response back to each requesting client, accordingly

About 4 connections are persistent (specific applications), then few other might be temporarily created (website access).

For reference, MySQL server version is 8.0.13-4, but I don’t have administrative access at all to it (only to my machine, where HAProxy resides).

Thank you.

On the website application (which also connects to the HAProxy), I get the following error instead: SQLSTATE[HY000] [2006] MySQL server has gone away.

Also, I’ve installed HAProxy on a local machine (same OS), and with the same configuration I can perfectly connect to the remote MySQL server, doing: mysql -u user -p'password' -h 127.0.0.1 -P 3307 -D database

Additionally, while the website application (on the affected host) is trying to connect (which lasts few seconds, then it fails), I can at least see the derived incoming connection at the MySQL side when executing show processlist.

Please, can anyone help me? I tried disabling firewall just in case and that made no effect (even when by TCP functioning one doesn’t need to explicitly allow the connection flow from a public server’s endpoint to the client).

This cannot be done.

Haproxy is not a mysql protocol multiplexer. What you need is something like ProxySQL.

Thanks, that makes it clear now