• MySQL知识库 :: performance
  • Slave with Duplicate Server ID

  • Description

    In a replication setup, all participating MySQL master and slave servers should have a unique server ID. Replication might work when two or more slaves have the same ID, but you might see some decrease in performance.

    The server ID is used for replication to enable master and slave servers to identify themselves, uniquely. While replication may work if two slaves have the same server ID, it could affect performance. Also, having them all unique can provide help in managing and monitoring the MySQL servers participating in the replication. Currently, a MySQL master server allows slaves with the same server-ID. This is a known problem, and could cause slaves to make several smaller relay logs files. Closing and opening files as a result will consequently slow down the replication process.

    You may be alerted to this condition by MySQL Monitor if you've setup a new slave duplicating the configuration file of another. Check the --server-id option in the configuration file.

    Best Practice

    To workaround around this problem, it is good to give all slaves a unique server-id. Typically, this is already done when setting up replication. To change the server ID, open the options file (my.cnf or my.cnf, depending on the system) on each slave with a text editor. Change or add the --server-id option to a unique server ID number for each slave. When finished each, restart the MySQL server. Below is an example of the --server-id option in the options file:

    [mysqld]
     server_id = <ID>

    The ID can be a positive integer from 0 to 4294967295 and should be unique within the replication group. When deciding on a slave's server ID, you might consider using the IP address's last digits. For instance, for an IP address for the server of 192.168.14.233, you could use 14233. Another choice could be something geographical. For instance, you could use the postal code of each server if they're in distant locations.