資料庫已建置完成,各種設定都已完成,但是在start slave ;的時候,報錯:
ERROR 1200 (HY000): The server is not configured as slave ; fix in config file or with CHANGE MASTER TO
這裡說,我沒有設定為從機,但我明明配置過的啊。
MySQL版本:5.6.19
「主:master IP : 172.17.210.199
從:slave IP :172.17.206.138
#17. 206.138的my.cnf
[root@liuyazhuang ~]# vi /etc/my.cnf [mysqld] datadir=/usr/local/mysql/data socket=/tmp/mysql.sock skip-grant-tables user=mysql # Disabling symbolic-links is recommended to prevent assorted security risks symbolic-links=0 tmpdir=/tmp [mysqld_safe] log-error=/usr/local/data/mysqld.log pid-file=/usr/local/mysql/data/mysqld.pid ###############以下是添加主从的配置 server_id = 2 log-bin = /usr/local/mysql/log/solve-bin.log master-host = 172.17.210.199 master-user = test master-pass = 123456 master-port = 3306 master-connect-retry = 60
這是MySQL主機172.17.210.199的my.cnf
[root@liuyazhuang ~]$ cat /etc/my.cnf [mysqld] log-bin = /u01/mysql/log/masters-bin.log read-only = 0 basedir = /u01/mysql datadir = /u01/mysql/data port = 3306 server_id = 1 socket = /tmp/mysql.sock join_buffer_size = 128M sort_buffer_size = 2M read_rnd_buffer_size = 2M sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES嘗試過多次重啟主從還是報錯;
接著手動chang to#
mysql> CHANGE MASTER TO MASTER_HOST='172.17.210.199', MASTER_USER='test', MASTER_PASSWORD='123456', MASTER_LOG_FILE='masters-bin.000003', MASTER_LOG_POS=120; Query OK, 0 rows affected, 2 warnings (0.04 sec)嘗試過多次重啟主從還是報錯;
接著手動chang to後來還是一樣報錯誤mysql> START slave;
在從庫伺服器執行START slave;指令啟動slave
mysql> mysql> SHOW VARIABLES LIKE 'server_id'; +---------------+-------+ | Variable_name | Value | +---------------+-------+ | server_id | 0 | +---------------+-------+ 1 row in set (0.00 sec)
報錯:
ERROR 1200 (HY000): The server is not configured as slave; fix in config file 或 CHANGE MASTER TO於是查看日誌1.查看SLAVE172.17.206.138上的Mysql報錯日誌,有這麼一句話:
141009 6:06:29 [ERROR] Server id not set, will not start slave
意思是,slave的server-id沒有設定。 那就奇怪了,我明明在設定檔裡面指定了server-id的了,而且有重啟mysql服務,難道不起效?
分別在主從上執行指令「show variables like 'server_id';」。
-------從機上面看埠
mysql> SHOW VARIABLES LIKE 'server_id'; +---------------+-------+ | Variable_name | Value | +---------------+-------+ | server_id | 1 | +---------------+-------+ 1 row in set (0.00 sec)
命名設定的是2,怎麼會變成0
##-------主機上面查看
mysql > SET GLOBAL server_id=2;
[root@liuyazhuang]# cat /etc/my.cnf [mysqld] datadir=/usr/local/mysql/data socket=/tmp/mysql.sock skip-grant-tables user=mysql symbolic-links=0 tmpdir=/tmp server_id = 2 log-bin = /usr/local/mysql/log/solve-bin.log master-host = 172.17.210.199 master-user = test master-pass = 123456 master-port = 3306 master-connect-retry = 60 [mysqld_safe] log-error=/usr/local/data/mysqld.log pid-file=/usr/local/mysql/data/mysqld.pid再次在從機172.17.206.138上執行slave start和show slave status,成功了。
但為什麼我之前修改了my.cnf檔案不起效?
仔細排查,發現配置裡面有[mysqld]和[mysqld_safe],之前將修改過的設定內容基本上都放在了[mysqld_safe]下面,新增的設定檔放的位置不一樣也有關係?於是我試著把設定檔裡修改的部分放在[mysqld]下面,於是改成這樣:
mysql> mysql> STOP slave; Query OK, 0 rows affected (0.05 sec) mysql> START slave; Query OK, 0 rows affected (0.00 sec)
如圖,就是將圖中標註的內容從[mysqld_safe]下修改到[ mysqld]下
以上是MySQL之-主從server-id不生效的範例程式碼(圖)的詳細內容。更多資訊請關注PHP中文網其他相關文章!