master and slave have equal MySQL server ids

  • 2020-05-30 21:12:43
  • OfStack

Mosquito took 1 master and 3 slave mysql copy this afternoon. As a result, after all the servers were configured, the following error was found


Last_IO_Error: Fatal error: The slave I/O thread stops because master and slave have equal MySQL server ids; these ids must be different for replication to work (or the --replicate-same-server-id option must be used on slave but this does not always make sense; please check the manual before using it).

server_id and my.cnf, server_id=1 in /etc/ my.cnf, server_id=1 in /etc/ my.cnf, I did not comment out the line (I set server_id in the copy section below), so I immediately commented out the line, then restarted mysql and found the same error.

View 1 server_id using the following command


mysql> show variables like 'server_id'; 
+---------------+-------+ 
| Variable_name | Value | 
+---------------+-------+ 
| server_id | 1 | 
+---------------+-------+ 
1 row in set (0.00 sec) 

It was found that mysql did not update server_id from the my.cnf file, so you had to modify it manually


mysql> set global server_id=2; # The sum here my.cnf In the setting of 1 Sample line  
mysql> slave start; 

After doing so, slave returned to normal.

But later mosquitoes use/etc/init d/mysqld restart restart mysql service, then look at slave state, find again the above error, then look at server_id found this value to 1 again.

After that, the mosquito checked the contents of etc/ my.cnf again, and confirmed that it should not be the problem of this file, so it went to google and found that mysql would look up /etc/ my.cnf, DATADIR/ my.cnf, USER_HOME/ my.cnf at startup.

So I did it


find / -name "my.cnf" 

The my.cnf file was found in /usr/local/mysql. The mosquito deleted the file and restarted the mysql service. If someone has a similar problem, try this.


Related articles: