You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

EC2上MySQL NDB Cluster从节点连接失败(ERROR 2002)求助

MySQL NDB Cluster从节点连接失败问题排查与解决

问题概况

在AWS EC2实例上部署多节点MySQL NDB Cluster后,主节点可通过以下命令正常连接:

mysql -u root -D mydb -h <master_ip> -P 3306

但使用从节点IP执行相同命令时,出现错误:

ERROR 2002 (HY000): Can't connect to server on '3.86.164.48' (115)

现有配置信息

主节点/etc/mysql/my.cnf

!includedir /etc/mysql/conf.d/
!includedir /etc/mysql/mysql.conf.d/

[mysqld]
# Options for mysqld process:
ndbcluster                      # run NDB storage engine
bind-address=0.0.0.0
skip-grant-tables

[mysql_cluster]
# Options for NDB Cluster processes:
ndb-connectstring=<master-ip-internal>  # location of management server

从节点/etc/my.cnf

[mysql_cluster]
# Options for NDB Cluster processes:
ndb-connectstring=<master-ip-internal>  # location of cluster manager

排查与解决步骤

  • 补全从节点SQL节点配置
    从节点作为SQL节点,缺少[mysqld]段的关键配置,导致mysqld未启用NDB引擎且未开放外部连接。修改从节点/etc/my.cnf,添加以下内容:

    [mysqld]
    ndbcluster
    bind-address=0.0.0.0
    skip-grant-tables
    

    修改完成后重启MySQL服务:

    systemctl restart mysql
    
  • 检查从节点MySQL服务状态
    确认MySQL服务正常运行:

    systemctl status mysql
    

    若服务未启动,执行启动命令并设置开机自启:

    systemctl start mysql
    systemctl enable mysql
    
  • 验证端口监听状态
    在从节点上检查3306端口是否被mysqld监听:

    netstat -tulpn | grep 3306
    

    需确保输出中显示0.0.0.0:3306或对应公网/内网IP的监听记录。

  • 检查AWS EC2安全组规则
    确保从节点安全组开放以下端口的入站规则:

    • 3306(MySQL客户端连接):允许你的客户端IP访问
    • 1186(NDB管理节点通信):允许主节点(管理节点)IP访问
    • 2202(NDB数据节点通信):允许集群内其他节点IP访问
      同时主节点安全组需开放对应端口的出站规则,确保集群节点间通信正常。
  • 检查集群节点状态
    在任意节点上执行以下命令查看集群状态,确认从节点已成功加入集群:

    ndb_mgm -e SHOW
    

    输出中需显示从节点作为SQL节点处于connected状态。

  • 排查本地连接与日志
    在从节点本地执行mysql -u root -D mydb,若本地连接失败,查看MySQL错误日志定位问题:

    cat /var/log/mysql/error.log
    

内容的提问来源于stack exchange,提问作者Simon Tran

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.07 03:25:35