问题描述
在主从复制中设置从库时报错:
Fatal error: The slave I/O thread stops because master and slave have equal MySQL server UUIDs; these UUIDs must be different for replication to work.
原因分析
为了模拟两台服务器,我直接复制了一个虚拟机,导致主库和从库的服务器UUID相同,从库会停止I/O线程以防止数据不一致。
解决方案
修改从库的UUID:
- 退出MySQL服务
- 修改auto.cnf中的server_uuid
vim ./var/lib/mysql/auto.cnf
- 重启mysqld
systemctl restart mysqld
- 重新登录MySQL
mysql -uroot -p1234
- 建立从库与主库的连接
change master to master_host='192.168.49.129', master_user='xiaoming', master_password='1234', master_log_file='mysql-bin.000001', master_log_pos=441;
- 启动从库
start slave;
- 查看从库状态
show slave status;
看到如下状态即为成功