我们的mysql版本是“mysql Ver 14.14 Distrib 5.1.35,for portbld-freebsd7.2(amd64)using 5.2”
我们有两个具有复制功能的数据库服务器,具有简单的主/从关系. mysql2是master,mysql1是slave.一年前,mysql是主人,mysql2是奴隶.我们不得不在硬件故障期间改变他们的角色.
在master上,我们显式设置了server_id(server-id)
[root@mysql2 ~]# grep server-id my.cnf
server-id = 2
[root@mysql2 ~]# mysql -e "SHOW VARIABLES LIKE 'server_id'"
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| server_id | 2 |
+---------------+-------+
但是,此设置未在my.cnf中设置为奴隶.
[root@mysql1 ~]# grep server-id my.cnf
哎呦.这应该没关系,因为server_id默认设置为1.
[root@mysql1 ~]# mysql -e "SHOW VARIABLES LIKE 'server_id'"
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| server_id | 1 |
+---------------+-------+
如果我重新启动mysql,那么复制将正常工作.
但是,如果我手动“STOP SLAVE”“START SLAVE”,我收到一个错误:
[root@mysql1 ~]# mysql -e "STOP SLAVE;"
[root@mysql1 ~]# mysql -e "START SLAVE;"
ERROR 1200 (HY000) at line 1: The server is not configured as slave; fix in config file or with CHANGE MASTER TO
当我没有在my.cnf中明确设置值时,为什么会出现此错误?为什么重新启动时复制工作,但是当我“停止SLAVE”时不复制“开始逃跑;”?
>看来mysql为变量server_id分配了一个默认值.
>根据默认的my.cnf,server_id将默认为1
# required unique id between 1 and 2^32 - 1
# defaults to 1 if master-host is not set
# but will not function as a master if omitted
#server-id = 1
修复是在my.cnf中明确设置server-id,正如Baron Schwartz在http://www.xaprb.com/blog/2007/08/01/why-mysql-server-not-configured-as-slave/所建议的那样
server-id=1
解决方法:
两个服务器不允许具有相同的server_id.另外,If you omit –server-id from a master, the default ID is 0, in which case a master refuses connections from all slaves, and a slave refuses to connect to a master.
有关更多信息,请访问see Section 15.1.1.2, “Setting the Replication Slave Configuration”.
即使两个服务器都有不同的server_id值,请确保新主服务器具有binary logging enabled.