1. 修改my.cnf文件
主: server_id = 1 # 1代表主
log-bin = master-bin
log-bin-index = master-bin.index
從: server_id = 2 # 2...代表從
relay-log = slave-relay-bin
relay-log-index = slave-relay-bin.index
2. 重啟數(shù)據(jù)庫 (my.cnf文件重新加載生效)
3. 建立主從關(guān)系
在主庫創(chuàng)建用戶并賦予其權(quán)限從主庫復(fù)制數(shù)據(jù),刷新用戶權(quán)限
CREATE USER ‘從庫使用的用戶名‘@'xx.xxx.xx.從庫ip' IDENTIFIED BY ‘password‘; GRANT ‘repl’ ON *.* TO‘從庫復(fù)制的用戶名‘@'xx.xxx.xx.從庫ip';
FLUSH PRIVILEGES;
4. 統(tǒng)一偏移量
①在主庫執(zhí)行 show master status;查看master數(shù)據(jù)庫當(dāng)前正在使用的二進(jìn)制日志及當(dāng)前執(zhí)行二進(jìn)制日志位置
②在從庫執(zhí)行
change master to master_host='主庫ip',master_user='從庫使用的用戶名',master_password='password',master_port=3306(默認(rèn)),
master_log_file='3306.000000'(在①中查詢的file數(shù)據(jù)),master_log_pos=200(在①中查詢的position數(shù)據(jù));
浙公網(wǎng)安備 33010602011771號(hào)