php-mqtt连接不成功

环境

  • EMQX 版本:5.1
  • 操作系统版本:windows

重现此问题的步骤

  1. 使用官方php-mqtt的代码连接云服务器成功
  2. 将地址账号密码修改为本地进行连接
  3. 控制台返回报错认证失败

    4.对EMQX进行日志追踪发现日志中账号密码显示未上传
    2023-09-09T03:26:10.895753+08:00 [MQTT] wanghaohan@127.0.0.1:51613 msg: mqtt_packet_received, packet: CONNECT(Q0, R0, D0, ClientId=wanghaohan, ProtoName=MQIsdp, ProtoVsn=3, CleanStart=false, KeepAlive=10, Username=undefined, Password=)
    2023-09-09T03:26:10.895856+08:00 [QUERY] wanghaohan@127.0.0.1:51613 msg: mysql_connector_received, connector: emqx_authn_mysql:1, sql: emqx_authn_mysql, state: [batch_inserts: , batch_params_tokens: , params_tokens: [emqx_authn_mysql: ], pool_name: emqx_authn_mysql:1, prepare_statement: [emqx_authn_mysql: SELECT password_hash FROM mqtt_user where username = ? LIMIT 1]]
    2023-09-09T03:26:10.896368+08:00 [AUTHN] wanghaohan@127.0.0.1:51613 msg: authenticator_result, authenticator: password_based:mysql, result: ignore
    2023-09-09T03:26:10.896368+08:00 [AUTHN] wanghaohan@127.0.0.1:51613 msg: authentication_result, reason: chain_result, result: {ok,{error,not_authorized}}
    2023-09-09T03:26:10.896368+08:00 [MQTT] wanghaohan@127.0.0.1:51613 msg: mqtt_packet_sent, packet: CONNACK(Q0, R0, D0, AckFlags=0, ReasonCode=5)
    2023-09-09T03:26:10.896470+08:00 [SOCKET] wanghaohan@127.0.0.1:51613 msg: emqx_connection_terminated, reason: {shutdown,not_authorized}

5、使用MQTTX测试连接,连接成功,查看日志追踪,发现账号密码是上传成功的

看描述已明确定位到是客户端没有传密码,建议自己debug一下客户端代码。