這篇文章主要介紹“MySQL搭建主從報(bào)錯(cuò)“The server is not configured as slave“怎么解決”,在日常操作中,相信很多人在MySQL搭建主從報(bào)錯(cuò)“The server is not configured as slave“怎么解決問題上存在疑惑,小編查閱了各式資料,整理出簡(jiǎn)單好用的操作方法,希望對(duì)大家解答”MySQL搭建主從報(bào)錯(cuò)“The server is not configured as slave“怎么解決”的疑惑有所幫助!接下來,請(qǐng)跟著小編一起來學(xué)習(xí)吧!
十余年的義烏網(wǎng)站建設(shè)經(jīng)驗(yàn),針對(duì)設(shè)計(jì)、前端、開發(fā)、售后、文案、推廣等六對(duì)一服務(wù),響應(yīng)快,48小時(shí)及時(shí)工作處理。全網(wǎng)營(yíng)銷推廣的優(yōu)勢(shì)是能夠根據(jù)用戶設(shè)備顯示端的尺寸不同,自動(dòng)調(diào)整義烏建站的顯示方式,使網(wǎng)站能夠適用不同顯示終端,在瀏覽器中調(diào)整網(wǎng)站的寬度,無論在任何一種瀏覽器上瀏覽網(wǎng)站,都能展現(xiàn)優(yōu)雅布局與設(shè)計(jì),從而大程度地提升瀏覽體驗(yàn)。成都創(chuàng)新互聯(lián)公司從事“義烏網(wǎng)站設(shè)計(jì)”,“義烏網(wǎng)站推廣”以來,每個(gè)客戶項(xiàng)目都認(rèn)真落實(shí)執(zhí)行。
ERROR 1200 (HY000): The server is not configured as slave; fix in config file or with CHANGE MASTER TO
這里說,我沒有配置為從機(jī),但我明明配置過的啊。
MySQL版本:5.6.19
主:master IP : 172.17.210.199
從:slave IP :172.17.206.138
先看看從機(jī)172.17.206.138的my.cnf
[root@testmysql ~]# 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 = my
master-pass = 123456
master-port = 3306
master-connect-retry = 60
這是MySQL主機(jī)172.17.210.199的my.cnf
[oracle@newbidb ~]$ 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
嘗試過多次 重啟主從還是報(bào)錯(cuò);
接著手動(dòng)chang to 后還是一樣報(bào)錯(cuò)
mysql> CHANGE MASTER TO
MASTER_HOST='172.17.210.199',
MASTER_USER='my',
MASTER_PASSWORD='123456',
MASTER_LOG_FILE='masters-bin.000003',
MASTER_LOG_POS=120;
Query OK, 0 rows affected, 2 warnings (0.04 sec)
mysql> START slave;
ERROR 1200 (HY000): The server is not configured as slave; fix in config file or with CHANGE MASTER TO
mysql> SHOW slave STATUS \G
*************************** 1. row ***************************
Slave_IO_State:
Master_Host: 172.17.210.199
Master_User: my
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: masters-bin.000003
Read_Master_Log_Pos: 120
Relay_Log_File: testmysql-relay-bin.000001
Relay_Log_Pos: 4
Relay_Master_Log_File: masters-bin.000003
Slave_IO_Running: No
Slave_SQL_Running: No
Replicate_Do_DB:
Replicate_Ignore_DB:
Replicate_Do_Table:
Replicate_Ignore_Table:
Replicate_Wild_Do_Table:
Replicate_Wild_Ignore_Table:
Last_Errno: 0
Last_Error:
Skip_Counter: 0
Exec_Master_Log_Pos: 120
----------------略
于是查看日志
1.查看SLAVE172.17.206.138上的Mysql報(bào)錯(cuò)日志,有這么一句:
141009 6:06:29 [ERROR] Server id not set, will not start slave
意思是,slave的server-id沒有設(shè)置。
那就奇怪了,我明明在配置文件里面指定了server-id的了,并且有重啟mysql服務(wù),難道不起效?
分別在主從上執(zhí)行命令“show variables like 'server_id';”。
-------從機(jī)上面查看端口
mysql> mysql> SHOW VARIABLES LIKE 'server_id';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| server_id | 0 |
+---------------+-------+
1 row in set (0.00 sec)
我就納悶?zāi)?,本來設(shè)置的是2,此時(shí)卻是0,
-------主機(jī)上面查看
mysql> SHOW VARIABLES LIKE 'server_id';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| server_id | 1 |
+---------------+-------+
1 row in set (0.00 sec)
跟設(shè)置的一樣。
既然參數(shù)文件不生效,就試試在數(shù)據(jù)庫命令里面設(shè)置:
在從機(jī) 172.17.206.138上執(zhí)行命令
mysql > SET GLOBAL server_id=2;
再次在從機(jī) 172.17.206.138上執(zhí)行slave start和show slave status,成功了。
注意?。?!由于“SET GLOBAL server_id=;”命令會(huì)在mysql服務(wù)重啟后丟失,所以一定要寫到配置文件里面。
但為什么我之前修改了my.cnf文件不起效?
仔細(xì)排查,發(fā)現(xiàn)配置里面有[mysqld]和[mysqld_safe],新增的配置文件放的位置不一樣也有關(guān)系?于是我嘗試把配置文件改成這樣:
"/etc/my.cnf" 24L, 467C written
[root@testmysql mysql]# 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 = my
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
修改之后,再次同步,成功了!
mysql>
mysql> STOP slave;
Query OK, 0 rows affected (0.05 sec)
mysql> START slave;
Query OK, 0 rows affected (0.00 sec)
到此,關(guān)于“MySQL搭建主從報(bào)錯(cuò)“The server is not configured as slave“怎么解決”的學(xué)習(xí)就結(jié)束了,希望能夠解決大家的疑惑。理論與實(shí)踐的搭配能更好的幫助大家學(xué)習(xí),快去試試吧!若想繼續(xù)學(xué)習(xí)更多相關(guān)知識(shí),請(qǐng)繼續(xù)關(guān)注創(chuàng)新互聯(lián)網(wǎng)站,小編會(huì)繼續(xù)努力為大家?guī)砀鄬?shí)用的文章!