# How to properly setup HAProxy with Percona XtraDB Cluster?

**URL:** <https://forums.percona.com/t/how-to-properly-setup-haproxy-with-percona-xtradb-cluster/30260>\
**Category:** Percona XtraDB Cluster 8.x\
**Tags:** percona\
**Created:** [May 11, 2024, 6:12pm UTC](https://forums.percona.com/t/how-to-properly-setup-haproxy-with-percona-xtradb-cluster/30260 "2024-05-11T18:12:34Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Narlandis](https://avatars.discourse-cdn.com/v4/letter/n/c57346/32.png) [@Narlandis](https://forums.percona.com/u/Narlandis)\
**Post date:** [May 11, 2024, 6:12pm UTC](https://forums.percona.com/t/how-to-properly-setup-haproxy-with-percona-xtradb-cluster/30260/1 "2024-05-11T18:12:34Z")

</div>

Can someone pls explain to the step by step of how to properly setup HAProxy with a XtraDB Cluster. I keep getting the same error:  
ERROR 2013 (HY000): Lost connection to MySQL server at ‘reading initial communication packet’, system error: 0

---

<div class="post-metadata">

**Author:** ![lalit.choudhary](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.percona.com/lalit.choudhary/32/51_2.png) [@lalit.choudhary](https://forums.percona.com/u/lalit.choudhary)\
**Post date:** [May 13, 2024, 5:49am UTC](https://forums.percona.com/t/how-to-properly-setup-haproxy-with-percona-xtradb-cluster/30260/2 "2024-05-13T05:49:55Z")

</div>

Hello @Narlandis

Here is the documentation for PXC and HAProxy configuration: [Load balancing with HAProxy - Percona XtraDB Cluster](https://docs.percona.com/percona-xtradb-cluster/8.0/haproxy.html)

---

<div class="post-metadata">

**Author:** ![meyerder](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.percona.com/meyerder/32/16994_2.png) [@meyerder](https://forums.percona.com/u/meyerder)\
**Post date:** [January 21, 2025, 7:33pm UTC](https://forums.percona.com/t/how-to-properly-setup-haproxy-with-percona-xtradb-cluster/30260/3 "2025-01-21T19:33:51Z")

</div>

Has to use the old password type… will not work with the new mysql auth…

---

<div class="post-metadata">

**Author:** ![lalit.choudhary](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.percona.com/lalit.choudhary/32/51_2.png) [@lalit.choudhary](https://forums.percona.com/u/lalit.choudhary)\
**Post date:** [January 24, 2025, 11:16am UTC](https://forums.percona.com/t/how-to-properly-setup-haproxy-with-percona-xtradb-cluster/30260/4 "2025-01-24T11:16:05Z")

</div>

Hello @meyerder

> Has to use the old password type… will not work with the new mysql auth…

Right,

The following is mentioned in the PXC doc for this issue: [Load balancing with HAProxy - Percona XtraDB Cluster](https://docs.percona.com/percona-xtradb-cluster/8.0/haproxy.html#install)

In Percona XtraDB Cluster 8.0, the default authentication plugin is `caching_sha2_password`. HAProxy does not support this authentication plugin. Create a mysql user using the `mysql_native_password` authentication plugin.

---

<div class="post-metadata">

**Author:** ![meyerder](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.percona.com/meyerder/32/16994_2.png) [@meyerder](https://forums.percona.com/u/meyerder)\
**Post date:** [January 24, 2025, 3:17pm UTC](https://forums.percona.com/t/how-to-properly-setup-haproxy-with-percona-xtradb-cluster/30260/5 "2025-01-24T15:17:20Z")

</div>

@lalit.choudhary Question… Instead of it doing a checkcluster remote web call How can I set it up to do something like this instead… as having another service dependency is In my opinion another breakage point…

I would “think” we could do something to say if this procedure returns/does not return a result mark it as down/up…

DELIMITER $$

USE `aa`$$

DROP PROCEDURE IF EXISTS `sp_aa`$$

CREATE DEFINER=`ae`@`%` PROCEDURE `sp_a`(eid VARCHAR(15))  
BEGIN  
DECLARE my\_wsrep\_local\_state\_comment VARCHAR(25);  
DECLARE my\_wsrep\_cluster\_status VARCHAR(25);  
DECLARE my\_read\_only VARCHAR(25);  
DECLARE my\_wsrep\_ready VARCHAR(25);

```
SELECT VARIABLE_VALUE INTO my_wsrep_local_state_comment FROM performance_schema.global_status WHERE VARIABLE_NAME = 'wsrep_local_state_comment';
SELECT VARIABLE_VALUE INTO my_wsrep_cluster_status FROM performance_schema.global_status WHERE VARIABLE_NAME = 'wsrep_cluster_status';
SELECT VARIABLE_VALUE INTO my_read_only FROM performance_schema.global_variables WHERE VARIABLE_NAME = 'READ_ONLY';
SELECT VARIABLE_VALUE INTO my_wsrep_ready FROM performance_schema.global_status WHERE VARIABLE_NAME = 'wsrep_ready';

IF
-- my_wsrep_local_state_comment IN ('Synced')
    my_wsrep_local_state_comment IN ('Synced','Donor/Desynced','Joining','Joined') 
    AND my_wsrep_cluster_status='Primary' 
    AND my_read_only='OFF' 
    AND my_wsrep_ready='ON'
THEN 
    SELECT my_wsrep_local_state_comment, my_wsrep_cluster_status, my_read_only, my_wsrep_ready;
END IF;

```

END$$

DELIMITER ;
