操作系统:CentOS Linux release 7.7.1908 (Core)
数据库系统:MySQL5.7.29
问题出现:
在虚拟机上配置MySQL的MHA集群时,在配置主从复制的时候发现失败:
mysql> show slave status\G;
Last_IO_Error: 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.
问题分析
问题提示主从使用了相同的server UUID, 一个个的检查:
检查主从server_id
主库:
mysql> show variables like 'server_id';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| server_id | 1 |
+---------------+-------+
1 row in set (0.01 sec)
从库:
mysql> show variables like 'server_id';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| server_id | 2 |
+---------------+-------+
1 row in set (0.01 sec)
Server_id不一样,排除。
检查主从状态:
主库:
mysql> show master status;
+------------------+----------+--------------+------------------+-------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set | +------------------+----------+--------------+------------------+-------------------+
| mysql-bin.000001 | 154 | | | |
+------------------+----------+--------------+------------------+-------------------+
1 row in set (0.00 sec)
从库:
mysql> show master status;
+------------------+----------+--------------+------------------+-------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set | +------------------+----------+--------------+------------------+-------------------+
| mysql-bin.000001 | 306 | | | |
+------------------+----------+--------------+------------------+-------------------+
1 row in set (0.00 sec)
File一样,排除。
最后检查发现它们的auto.cnf中的server-uuid是一样的。
[root@localhost ~]# vim /var/lib/mysql/auto.cnf
[auto]
server-uuid=4f37a731-9b79-11e8-8013-000c29f0700f
问题解决
停止从库的mysqld服务,删除他的auto.cnf文件,再启动数据库服务即可:
[root@localhost mysql]# systemctl stop mysqld.service
[root@localhost mysql]# mv /var/lib/mysql/auto.cnf /var/lib/mysql/auto.cnf.bak
[root@localhost mysql]# systemctl start mysqld.service
此时再去查看从库auto.cnf,已自动生成新的server-uuid:
[root@localhost mysql]# vim /var/lib/mysql/auto.cnf
[auto]
server-uuid=2682888d-994a-11e8-aaf0-000c298cdafc
再查看从库状态,已正常。