报错:a slave with the same server_id as this slave has connected to the master
已经有一台使用相同 server_id 的从库连接到主库,主库拒绝当前从库的 IO 连接。
MySQL 复制协议:集群内所有实例 server_id 必须全局唯一,主库检测到重复 server_id,直接踢掉后接入的从库,从库 IO 线程报错。
现象
从库 show slave status\G
Slave_IO_Running: Connecting / Preparing
Last_IO_Error: a slave with the same server_id as this slave has connected to the master
根因 3 种场景
- 两台从库配置了一模一样的 server_id(最常见)
- 同一台机器多次启动 MySQL 实例,my.cnf 重复、server_id 写重
- 旧的从库实例没下线,还在运行,新从库复用了它的 server_id
⚠️注意:
server_id=0也是特殊值,不允许做从库。
排查步骤
1)各个从库检查本机 server_id
show variables like 'server_id';
所有主、从实例,server_id 必须全部不一样,取值 1‑2^32。
2)在主库查看当前所有复制连接,确认是谁占用这个 id
主库执行:
show processlist;
找到 Command=Binlog Dump 的线程,这些就是从库 IO 连接。
Id | User | Host | db | Command | Time | State | Info
xxx| repl | x.x.x.x:xx | NULL | Binlog Dump | xxx | Master has sent all binlog to slave; waiting for binlog to be updated | NULL
看 Host 列,可以看到占用该 server_id 的从库 IP。
主库没有直接展示对端 server_id,但是可以通过来源 IP 定位机器。
修复方案
方案 A:修改冲突从库的 server_id(推荐)
- 修改 my.cnf
[mysqld]
server_id=102 #改成一个集群内没有使用过的数字
- 重启 MySQL 服务
systemctl restart mysqld
- 重启复制
stop slave;
start slave;
⚠️只改内存参数 set global server_id 不生效!server_id 是静态参数,必须改配置文件 + 重启 mysqld。

浙公网安备 33010602011771号