1. 程式人生 > >mysql 新增從服務器配置出錯

mysql 新增從服務器配置出錯

mysql

新增一臺從服務器配置完
server-id = 117
log-bin = mysql-bin
binlog-format = mixed
relay-log = mysql-relay
grant replication client,replication slave on . to centos7@‘192.168.0.%‘ identified by ‘centos7‘;
change master to
master_host = ‘192.168.0.106‘,
master_user = ‘centos7‘,
master_password = ‘centos7‘,
master_log_file =‘mysql-bin.000002‘,
master_log_pos =106;

執行start slave出現 The server is not configured as slave; fix in config file or with CHANGE MASTER TO錯誤
執行show variables like ‘server_id‘;查看
技術分享圖片
server-id為0,servier-id為117怎麽會是0?
執行命令“SET GLOBAL server_id=117;”這樣可以解決
不過SET GLOBAL server_id=;”命令會在mysql服務重啟後丟失,所以一定要寫到配置文件裏面。
仔細排查,發現配置裏面有[mysqld]和[mysqld_safe],新增的配置文件放的位置不一樣也有關系?於是我嘗試把配置文件改成這樣再嘗試一下

將safe的配置文件放到mysqld上
技術分享圖片
重啟服務器
再次執行start slave;
報錯The server is not configured as slave; fix in config file or with CHANGE MASTER TO
這是因為上次的配置還在使用,重置一下
執行reset slave
技術分享圖片
如果還出錯可以將配置產生的文件刪除重新配置。
一定要註意
master_log_file =‘mysql-bin.000002‘,
master_log_pos =106;
這兩個選項使用show master status;查看
技術分享圖片
主服務器運行中並且有一定的數據再加入從服務器:
此過程要先把主服務器的數據備份出來,然後拷貝到從服務器上導入到從服務器的數據庫,然後在讓從服務器從主服務器的指定位置開始備份數據即可。

ubuntu下的配置
不要在my.cnf下配置或者把下面的命令加入到最下面
最好在/etc/mysql/mysql.conf.d/mysqld.cnf下配置
ubuntu從服務器
要在/etc/mysql/mysql.conf.d/mysqld.cnf下配置否者不生效
註意安全模式
[mysqld_safe]
不要在這裏配置
在下面的mysqld配置
放到最後面
server-id = 114
log-bin = mysql-bin
binlog-format = mixed
relay-log = mysql-relay
主服務器上加權限
grant replication client,replication slave on . to ubuntu1@‘192.168.0.%‘ identified by ‘ubuntu1‘;
從服務器上加入下面指令
change master to
master_host = ‘192.168.0.106‘,
master_user = ‘ubuntu1‘,
master_password = ‘ubuntu1‘,
master_log_file =‘mysql-bin.000003‘,
master_log_pos =2536;

一定要使用如下命令啟動從服務器
start slave;

mysql 新增從服務器配置出錯