# MySQL proxy errors

**URL:** <https://discourse.haproxy.org/t/mysql-proxy-errors/7006>\
**Category:** Help!\
**Created:** [October 19, 2021, 11:03pm UTC](https://discourse.haproxy.org/t/mysql-proxy-errors/7006 "2021-10-19T23:03:45Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Adrianilloo](https://avatars.discourse-cdn.com/v4/letter/a/f14d63/32.png) [@Adrianilloo](https://discourse.haproxy.org/u/Adrianilloo)\
**Post date:** [October 19, 2021, 11:03pm UTC](https://discourse.haproxy.org/t/mysql-proxy-errors/7006/1 "2021-10-19T23:03:45Z")

</div>

Hi,

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

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

```

My config:

```auto
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.

---

<div class="post-metadata">

**Author:** ![Adrianilloo](https://avatars.discourse-cdn.com/v4/letter/a/f14d63/32.png) [@Adrianilloo](https://discourse.haproxy.org/u/Adrianilloo)\
**Post date:** [October 20, 2021, 10:11pm UTC](https://discourse.haproxy.org/t/mysql-proxy-errors/7006/2 "2021-10-20T22:11:17Z")

</div>

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).

---

<div class="post-metadata">

**Author:** ![lukastribus](https://avatars.discourse-cdn.com/v4/letter/l/7ea924/32.png) [@lukastribus](https://discourse.haproxy.org/u/lukastribus)\
**Post date:** [October 21, 2021, 2:32pm UTC](https://discourse.haproxy.org/t/mysql-proxy-errors/7006/3 "2021-10-21T14:32:00Z")

</div>

> [@Adrianilloo](#):
>
> Here are my requirements:

This cannot be done.

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

---

<div class="post-metadata">

**Author:** ![Adrianilloo](https://avatars.discourse-cdn.com/v4/letter/a/f14d63/32.png) [@Adrianilloo](https://discourse.haproxy.org/u/Adrianilloo)\
**Post date:** [October 22, 2021, 6:53am UTC](https://discourse.haproxy.org/t/mysql-proxy-errors/7006/4 "2021-10-22T06:53:02Z")

</div>

Thanks, that makes it clear now
