haproxy连接数据库时Lost connection to MySQL server at ‘reading initial communication packet', system er...

写在最前面的话:

今天删除了pxc数据库集群,然后重新创建了pxc集群,之后连接h1h2时突然报错Lost connection to MySQL server at ‘reading initial communication packet', system error: 0

解决思路:

1、查看日志

docker logs h1

2、分析日志

[WARNING] 098/144528 (1) : Exiting Master process...
[WARNING] 098/144531 (8) : Stopping proxy admin_stats in 0 ms.
[WARNING] 098/144531 (8) : Stopping proxy proxy-mysql in 0 ms.
[WARNING] 098/144531 (8) : Stopping frontend GLOBAL in 0 ms.
[WARNING] 098/144531 (8) : Proxy admin_stats stopped (FE: 2 conns, BE: 1 conns).
[WARNING] 098/144531 (8) : Proxy proxy-mysql stopped (FE: 7 conns, BE: 7 conns).
[WARNING] 098/144531 (8) : Proxy GLOBAL stopped (FE: 0 conns, BE: 0 conns).
[ALERT] 098/144532 (1) : Current worker #1 (8) exited with code 0 (Exit)
[WARNING] 098/144532 (1) : All workers exited. Exiting... (0)
[NOTICE] 098/144628 (1) : New worker #1 (8) forked
[WARNING] 098/144628 (8) : Server proxy-mysql/MySQL_1 is DOWN, reason: Layer7 wrong status, code: 0, info: "Access denied for user 'haproxy'@'h1.net1' (using password: NO)", check duration: 0ms. 4 active and 0 backup servers left. 0 sessions active, 0 requeued, 0 remaining in queue.
[WARNING] 098/144629 (8) : Server proxy-mysql/MySQL_2 is DOWN, reason: Layer7 wrong status, code: 0, info: "Access denied for user 'haproxy'@'h1.net1' (using password: NO)", check duration: 0ms. 3 active and 0 backup servers left. 0 sessions active, 0 requeued, 0 remaining in queue.
[WARNING] 098/144629 (8) : Server proxy-mysql/MySQL_3 is DOWN, reason: Socket error, info: "Broken pipe", check duration: 0ms. 2 active and 0 backup servers left. 0 sessions active, 0 requeued, 0 remaining in queue.
[WARNING] 098/144629 (8) : Server proxy-mysql/MySQL_4 is DOWN, reason: Layer7 wrong status, code: 0, info: "Access denied for user 'haproxy'@'h1.net1' (using password: NO)", check duration: 0ms. 1 active and 0 backup servers left. 0 sessions active, 0 requeued, 0 remaining in queue.
[WARNING] 098/144630 (8) : Server proxy-mysql/MySQL_5 is DOWN, reason: Layer7 wrong status, code: 0, info: "Access denied for user 'haproxy'@'h1.net1' (using password: NO)", check duration: 1ms. 0 active and 0 backup servers left. 0 sessions active, 0 requeued, 0 remaining in queue.
[ALERT] 098/144630 (8) : proxy 'proxy-mysql' has no server available!

上面的错误中有段错误提示using password: NO,让我想起安装Haproxy负载均衡三时要创建haproxy账号,来登录数据库发送心跳检测,因为集群节点都被删除了,所以这个账号也不存在
3、创建haproxy账号

create user 'haproxy'@'%' identified by '';

4、如果你的问题不是处于dock环境,那可以尝试以下解决办法:

第一步:找到:my.cnf文件

find / -name my.cnf

第二步:修改my.cnf文件

vi my.cnf
--------方式一、增加------------------
skip-name-resolve #跳过DNS反向解析过程.(这样就不能使用主机名连接mysql了,只能使用ip连接)
--------方式二、修改-----------------------------
找到bind-address,把127.0.0.1改成0.0.0.0或者注释掉该行

第三步、重启

你可能感兴趣的:(haproxy连接数据库时Lost connection to MySQL server at ‘reading initial communication packet', system er...)